If anyone is still interested (I'm sure many are), there is
some documentation about the memory manager. Is also a description of the "
cmem" manager, which is in a separate compiler package.
By the way, in the compiler folder "
<fpc-scr-dir>\packages\libgc\src\gcmem.pp" there is another one : "
Boehm garbage collector memory manager".
In the source code of "
heap.inc" I see a very detailed comment (one of many):
Fixed os chunks can be converted to variable os chunks and back
(if not too big). To prevent repeated conversion overhead in case
of user freeing/allocing same or a small set of sizes, we only do
the conversion to the new fixed os chunk size format after we
reuse the os chunk for another fixed size, or variable. Note that
while the fixed size os chunk is on the freelists.oslist, it is also
still present in a freelists.fixedlists, therefore we can easily remove
the os chunk from the freelists.oslist if this size is needed again; we
don't need to search freelists.oslist in alloc_oschunk, since it won't
be present anymore if alloc_oschunk is reached. Note that removing
from the freelists.oslist is not really done, only the recycleflag is
set, allowing to reset the flag easily. alloc_oschunk will clean up
the list while passing over it, that was a slow function anyway.
But the repository history will show the maximum amount of information. For example, running [
git log "*heap.inc"] shows many interesting commits (it is curious to see them with dates:
--format="%cs %s"). You can see how improvements for multithreading were added, block sizes were changed, bugs were fixed... There are even recent commits.