Most resources that are allocated arbitrarily in Freecell Solver are allocated in a compact manner. I.e: instead of being individually malloced, they are allocated in segments and placed one after the other. The segments are dynamically allocated and kept at a fixed location in memory. If more memory is needed, another segment is allocated.
The module that is responsible for this is:
alloc.c
/alloc.h
-
allocates blocks of arbitrary size in a compact manner.
It supports releasing the last allocated block and the last one alone.
Compact allocation is used for the following resources.
States - a derived state is allocated using the hard thread's allocator, and it is modified with the appropriate moves. If it is found to have already existed, it is released. Else, it is kept and a pointer to it can be found in the states collection.
Card stacks - if a card stack was modified, it is compactly allocated (see (*Mark COMPACT_ALLOC_CARD_STACKS*) ), before one checks to see if it is present in the stacks collection. If it was found there, its memory is released. Else, it is kept there.
Move stacks - the move stacks leading to the parent are compactly allocated (see (*Mark COMPACT_ALLOC_MOVE_STACKS*)).
Hash Elements - The elements of the hash linked lists are compactly allocated with a hash-wide hash allocator.