Implementing a first-fit memory allocator in C++
This medium-difficulty coding problem tests whether you can build a working memory allocator from scratch—a cornerstone skill for systems programming roles at quant firms and trading platforms. You are given fixed capacity and must manage allocation, deallocation, and validation of memory blocks efficiently.
The key challenges are: implementing the first-fit search strategy to locate free chunks, tracking allocated vs. free memory using the provided header structures, validating that deallocations target only memory your allocator owns, and keeping the allocator object itself under 24 bytes. You must also handle the boundary between unallocated (marked with a magic sentinel) and truly allocated memory, and throw std::bad_alloc() when appropriate.
- Free-list traversal and chunk metadata design
- First-fit placement strategy
- Memory validation and ownership tracking
- Exception safety and edge cases (zero-size allocations, exhausted capacity)
- Object size constraints via careful member selection