lucas roguski

projects repository

September 27th, 2011

CustomAlloc is a small project about designing own custom allocator, desirably more efficient than standard allocator provided in standard C++ library.

Basically, allocator should acquire a big chunk of memory from OS and split the available memory between used containers, remembering about proper memory deallocations. CustomAlloc defines a 2-level memory hierarchy, in which acquired block of memory from OS is virtually split into memory pages and those are again split into memory chunks, being the fundamental portions of available memory. Each memory page contains also some control data, holding information about page occupancy.

Memory hierarchy

When a new memory is being requested by container, CustomAlloc first checks whether there’s any available free left in the last used page. On failure, the manager iterates through next available pages, checking for free chunks. This time, on failure, memory manager tries to clean up dirty pages in order to regain free space and if this step does not help — manager acquires a new memory block from OS.

Source code with benchmark results is available >here<.

Comments are closed.