[fpc-devel] RTL: high CPU load in heap manager

Adriaan van Os fpc at microbizz.nl
Tue Nov 11 10:28:16 CET 2014

Jonas Maebe wrote:
> On 10/11/14 18:47, Karoly Balogh (Charlie/SGR) wrote:
>> We were profiling our code, and one RTL function regularly popped up in
>> close to the top in the profiling list.
>> It's remove_freed_fixed_chunks(). Can someone explain to me under what
>> condition this code is triggered very often and/or could take long to
>> execute (there's a loop in there)?
> This was reported earlier too, but I couldn't reproduce it:
> http://bugs.freepascal.org/view.php?id=18079 (especially comment 47405
> by Sergei).

I suggest to use cmem and compare the results.

I will also note that malloc uses mremap <http://man7.org/linux/man-pages/man2/mremap.2.html> on 
Linux only, rather than physically moving bytes around. This makes a very efficient realloc 
possible (on Linux only).

The Mach kernel of Mac OS X has vm_remap, but Apple is not smart enough to use it (as of OS X 
10.8.5, the source code for malloc in OS X 10.9 is unknown).

Windows neither has a mremap nor a realloc, which implies that on every resize a new block  has to 
be allocated, with all bytes physically moved to the new location, see 
<http://www.mgroeber.de/misc/windows_heap.html>. This makes realloc on Windows (with the system 
heap manager) extremely ineffcient.


Adriaan van Os

More information about the fpc-devel mailing list