[fpc-pascal]Memory Usage

James Mills prologic at prologitech.com
Mon May 12 11:00:07 CEST 2003

On Mon, May 12, 2003 at 09:47:07AM +0200, Marco van de Voort wrote:
> > I'd like to know why one of my programs pircsrv written in FPC uses up so
> > much memory. 107Mb of virtual memory (so it seems) and 7Mb of data. Here
> > is the top stats...
> Two possibilities:
> - memory leaks.  Proceed as Peter already explained.
But a 100Mb odd memory leak ? How is this possible, my program only has
a handlefull of getMem and reAllocMem calls throughout it.

> - heap fragmentation. Use unit cmem, or if you use a lot of small same
> 	size reallocations, pool them and reuse (often even faster)
> The second needs some explaining. The default FPC heapmanager never releases
> memory back to the system. Of course it tries to reuse the memory if
> possible, but sometimes with weird allocation schemes this can lead to a
> race in long running programs. (like daemons)

Not releasing memory back to the system, isn't this bad ?


> All this is because of performance reasons. Memory allocation is close to
> being the slowest thing a program can do itself (calling the OS is of course
> slower).
> The cmem unit links in libc, and uses the C primary memory allocations
> routines. Note that if you use libc anyway for some reason, it will also avoid
> having two heaps. (a libc and a fpc-rtl one)
> The libc memory manager is much slower, but has less problems with strange
> memory allocation patterns. It is also probably a bit more secure.
> In general keep using the FPC memory manager, unless this kind of behaviour
> happens (usually only in daemon programs that allocate/deallocate memory all
> the time), and then either switch to libc, or try to fix the odd memory
> patterns. (e.g. by pooling)
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

More information about the fpc-pascal mailing list