[fpc-pascal] heap size growing

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Jan 14 18:08:47 CET 2009


On 14 Jan 2009, at 13:02, Burkhard Carstens wrote:

> Am Mittwoch, 14. Januar 2009 04:50 schrieb Seth Grover:
>>
> I had the same problem. You could try to enable "BESTMATCH" in the  
> heap
> manager by either compiling the rtl with "-dBESTMATCH" or changing
> "{ define BESTMATCH}" to "{$define BESTMATCH}" in rtl/inc/heap.inc and
> see if the situation improves. For me, it improved but didn't solve  
> the
> problem completely. I had to create my own mem pool for some  
> frequently
> allocated/freed structures.

In the general/average case, "best fit" produces slightly worse  
results than "first fit" (which is the default). The reason is that's  
you're more likely to end up with a bunch of unusably small blocks  
over time than with first fit (there are of course usage patterns in  
which this does not hold).

> IIRC this was caused by usage pattern like this:
> * free a huge chunk (a) of mem -> chunk is returned to heap manager
> * allocate small chunk -> this results in heap manager splitting chunk
> (a) to return the small piece (b)
> * now allocating again a huge chunk (same size as (a)) results in heap
> manager requesting a new chunk of mem from OS because the remainder of
> (a)-(b) is not sufficient.
> .. well, in short: memory fragmentation
> With BESTMATCH enabled, the heap manager tries harder to find a small
> free block for (b) before splitting (a) ..
>
> However, I am not completely sure if this is the same problem ..

It probably is.

> it
> could also be caused by the reworked heap manager, which now handles
> mem allocation per thread (if that's allready in 2.2.2 ??) ..

No, it is not. It will only be released in 2.4.0. And it will not  
solve the problem, unless the differently-sized memory blocks are only  
allocated in different threads.

You can also try using your platform's libc memory manager to see  
whether it deals better with this usage pattern (add "uses cmem" to  
the uses clause of your main program). Or, as mentioned above, use  
your own memory pool (like the default memory manager already does for  
small allocations).


Jonas



More information about the fpc-pascal mailing list