![]() |
S.16 Advanced Memory Management: The Chunked FDA Approach |
In SheerPower, all data values are stored in a
Fixed Data Area (FDA). To manage this memory with
extreme performance, SheerPower uses a custom memory allocator
known as the Chunked FDA. This system is engineered to bypass the
limitations of standard library allocators (like
malloc
) and eliminate the unpredictable pauses
associated with garbage collectors found in many other high-level
languages.
This advanced tutorial explores the architecture of the Chunked FDA, revealing how it achieves its speed and efficiency through chunking, size classes, and aggressive memory reuse.
The FDA avoids the high cost of frequent system calls by requesting large chunks of memory from the operating system at once. It then sub-allocates smaller pieces from these chunks to the application.
To manage these sub-allocations efficiently, the FDA uses two key strategies:
allocate_fda(64)
When deallocate_fda()
is called, the block is pushed
back onto the Free List stack for near-instant reuse.
Every memory block allocated by the FDA is preceded by a small, hidden header. This header stores metadata that the allocator uses to manage the block efficiently.
This structure allows deallocate_fda()
to know
exactly which free list to return the block to without needing
any extra parameters from the programmer.
allocation_id
stored in each block header, combined
with the built-in logging and replay testing features, makes it
possible to track the lifecycle of every single memory block,
simplifying the diagnosis of complex memory bugs.
Hide Description
|
|
Enter or modify the code below, and then click on RUN |
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |