Hi Thierry,
Could you enlighten me on how MacOS 9.1 allocates RAM?
I always thought that the Preferred memory size you specify for an
application is the maximum it ever has access to, even if there is more
available ram and it needs more to load data in.
I just noticed for the first time ever that IDL's taken up more ram as I
loaded more and more data into it, and it is way beyond the 128mb I gave it
as Preferred size.
So, MacOS 9.1 actually does dynamic memory allocation? Is the reason I never
saw this before is that I never really had much ram in my system? (I just
added 256 Mb to the total of 448 Mb).
Pavel
Hi Pavel,
You are mostly correct. OS 9 (and it's ancestors) use a fixed size heap system for application memory.
This means that when you launch an app, the process manager will attempt to allocate a block of memory that is at least as large as the minimum memory size and no more than the preferred size. If there is not enough contiguous memory to allocate the minimum size, the process manager will put up an error dialog about not enough memory. If there is enough memory for the minimum size but less than the preferred size, the process manager will allocate what it can leaving some 500KB for system use.
In a normal OS 9 App, once that heap has been allocated, all memory allocations will come from it.
In IDL however, I take advantage of the fact that on most systems, there is a pool of unused memory available (memory not reserved to any running process). Apple calls this pool temporary memory. When an allocation is requested in IDL I go through the following sequence to try and get that memory:
If the allocation can happen from IDL's fixed memory heap and would leave a minimum amount of free memory in said heap (About 1MB or so) then it will get the memory from there.
If the allocation is bigger than the free memory remaining in IDL's heap, or it would leave too little free memory in IDL's heap for system allocations that need to come from it, then I will attempt to allocate from the temporary memory pool. When this happens, you will see IDL's memory use go up.
One way to see this, is to allocate a huge variable like
a = findgen( 100000000 )
or something big enough to flow out of the fixed heap with the about this computer window visible. You should see IDL grab unused system ram to satisfy the request.
Then delete the variable
a = ''
and you should see IDL's memory partition return to normal.
I spent many years (5 to be exact), tweaking IDL's memory usage on Classic, there have been at least 7 different allocators for Mac over that period. Around 5.3, it stabilized, and has worked well for most things so I haven't touched it except to force 16 byte alignment of allocation for Altivec in 5.4.
Hope this clears things up a bit.
Thierry