iakov.dev

A pool allocator for small objects

· 1 min read

Little Zombie Susie screenshot

The standard C++ allocator usually keeps free memory chunks in a linked list, so finding a free chunk isn’t fast, and small objects suffer the most. I decided to speed up allocation with a dedicated pool allocator. Every small object in the engine now derives from a base class that takes its memory from the pool and gives it back there.

Memory allocation for small objects is now three times faster.

The idea comes from Andrei Alexandrescu’s Modern C++ Design. His small-object allocator is explained in detail here.