Master the fundamental concepts of memory optimization through this focused micro-challenge.
General-purpose malloc carries metadata, coalescing, and thread-cache logic. Games, network stacks, and kernels use memory pools when objects are one size and lifetimes are short. PostgreSQL buffer pools and slab allocators in Linux follow the same pattern at different scales.
Preallocate a slab of N objects. Free list threads through objects with an embedded next pointer. Allocate and free are pointer swaps.
cLoading…
Keep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will implement a fixed-size memory pool with allocate and free in O(1). This exercise asks you to beat malloc on a microbenchmark creating many same-sized objects.
Implement memory pool for fixed-size objects with O(1) allocation/deallocation.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github