Xojo Conferences
XDCMay2019MiamiUSA

allocation conflict (Real Studio Plugins Mailinglist archive)

Back to the thread list
Previous thread: REALGraphics calls dont clip on a plugin control
Next thread: Seeking sugguestions for file catalog


macosx and unix paths   -   GOLD
  allocation conflict   -   Thomas Tempelmann
   Re: allocation conflict   -   Christian Schmitz
    Re: allocation conflict...   -   Thomas Tempelmann
     Re: allocation conflict...   -   Alfred Van Hoek
     Re: (offlist) Re: allocation conflict...   -   Jonathan Johnson
    Re: allocation conflict...   -   Thomas Tempelmann

allocation conflict
Date: 12.06.04 01:02 (Sat, 12 Jun 2004 02:02:01 +0200)
From: Thomas Tempelmann
I'm seeing slowdowns and unexpected quits in my
complex app. Here's why:

I'm using MSL classes such as "map" in my plugin.

By default, "map" uses its own allocator, which takes
memory in chunks from the available Mac OS or Windows
heap and manages it.

When RB's runtime needs money, it does the same thing.

So, both the RB runtime and the plugin make a run for
getting memory from the same source, but do not share
it with each other when they don't need it any more.

This leads, as I can see in various cases, to an eventual
slowdown because more and more virtual memory gets used
up, even though the "used" memory of both the MSL and
the RB runtime are not going up over time - they just
reallocate their pools all the time.

On OS 9, this is even worse, because it eventually leads
to the app being quit because it rans out of memory
(because the MSL has taken it over).

So, what I'd need to do is to let the MSL use the very
same memory pool that RB's runtime does, so that if
one frees some of it, the other can use it again.

Unfortunately, there's no such function exported from the
plugin API.

Can someone tell me how I could solve this? I learned
that at least on OS X, RB 5 is using malloc directly,
not managing its own pool any more. But what about Windows
and OS 9? Plus, since I'm still working with RB 4.5.3,
what allocation functions did its runtime use? Did it
do its own management? And if so, can I find it in the
lib somehow so that I can use it in the plugin, too?

Thomas

Re: allocation conflict
Date: 12.06.04 12:24 (Sat, 12 Jun 2004 13:24:03 +0200)
From: Christian Schmitz
Thomas Tempelmann <<email address removed>> wrote:

> Can someone tell me how I could solve this? I learned that at least on OS
> X, RB 5 is using malloc directly, not managing its own pool any more. But
> what about Windows and OS 9?

You could write a memory allocator for MSL which uses Memoryblocks or
Strings from RB to do it's work.

BTW, I don't think that two malloc libs should be a problem on Mac OS X
or Windows.

Mfg
Christian

Re: allocation conflict...
Date: 13.06.04 15:59 (Sun, 13 Jun 2004 16:59:55 +0200)
From: Thomas Tempelmann
Thanks, Alfred, Jon and Aaron, for your help.

In the mean time, I had installed a different allocator
for the "new" operator which uses its own, separate,
memory pool (I'm using Temp Mem), so that I can verify that
it's not the allocations my plugin makes that lead to the
increasing memory loss.

And what I found is quite disturbing. I'd appreciate it if
someone from RS can have a close look at what I describe here,
because it might be a systematic error in the memory allocation
that RB uses:

I'm losing about 4-5 MB of RAM per re-load of my data!

And there's no "dangling" objects (i.e. circular refs), due
to DebugDumpObjects: After each reload of my data the number
of objects remain the same.

Here's what I used in order to see the memory loss:

I look at two values:
1. FreeMem() from InterfaceLib
2. System.MemoryUsed

Both values change significantly each time:

FreeMem decreases by 7 MB, while UsedMem increases by 4 MB.

So I see two problems here:
a) why is the used mem going up each time?
b) why is the difference between free and used memory
increasing by another 3 MB each time?

To answer problem (b):

Can someone from RS please explain how System.MemoryUsed
gets its value? I guess it works like this:

RB manages its own memory pool. When this pool gets used
up, it increases its pool by getting more memory from the system.
Each time this happens, FreeMem() decreases.

This RB-managed pool has free and used chunks. I suspect
that System.MemoryUsed tells me the sum of the used chunks
therein.

Is that correct?

If so, that means that my values above show quite a significant
memory fragmentation, or that the pools get increased before
the freed chunks in the older pool areas are re-used.

And for problem (a), well, I have no idea how to find the leak(s).
Any suggestions how I could figure out what's leaking,
given that DebugDumpObjects is not showing any leaks?

Thomas

Re: allocation conflict...
Date: 13.06.04 16:55 (Sun, 13 Jun 2004 11:55:00 -0400)
From: Alfred Van Hoek
on 6/13/04 10:59 AM, Thomas Tempelmann at <email address removed> wrote:

> So I see two problems here:
> a) why is the used mem going up each time?
> b) why is the difference between free and used memory
> increasing by another 3 MB each time?

As I understood from your previous postings, you are using functions of an
MSL lib which require you to allocate memory. Do you need to load the
library during runtime? Is the lib asking for memory (possibly by
callbacks)? If that is the case you'll always will have troubles if you are
going to use the platform specific functions. You are in the RB environment
and you should request memory from the RB runtime. The only existing way to
do so is by using memoryblocks, which RB understands. That way you are not
clashing with RB, and the code I posted is above all not evil, and allows
you to handle memory.

Of course the whole argument is moot, if the premise was wrongly
interpreted...

Alfred

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: allocation conflict...
Date: 13.06.04 17:54 (Sun, 13 Jun 2004 18:54:59 +0200)
From: Thomas Tempelmann
Alfred,

>> So I see two problems here:
>> a) why is the used mem going up each time?
>> b) why is the difference between free and used memory
>> increasing by another 3 MB each time?
>
>As I understood from your previous postings, you are using functions of
>an MSL lib which require you to allocate memory.

No, you misunderstood me.

The memory loss appears to be _independent_ from allocating
memory in my plugin, and I've proven that by doing the plugin's
allocation in a separate memory pool that is not affecting the
free or used memory as shown.

Thomas