CookMem 1.4.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
References

Core Backend Components

Memory Arenas

Memory arena classes are used to obtain large chunks of memory. A memory arena can be shared by multiple memory contexts.

These classes implement the cookmem::MemArena interface without explicitly inheriting from it. This avoids the overhead of virtual function calls and allows the functions to be inlined.

Memory Logger

Memory logger classes are used to log memory context activities.

These classes implement the cookmem::MemLogger interface without explicitly inheriting from it. This avoids the overhead of virtual function calls and allows the functions to be inlined.

Memory Pool

The memory pool allocates and deallocates smaller chunks of memory within the segments obtained from memory arenas.

Currently, there is only a single implementation.

Memory Contexts

Memory context classes contain the API that users call to allocate and deallocate memory. They use the backend cookmem::MemArena, cookmem::MemLogger and cookmem::MemPool to do the actual work.

The backend components can be mixed and matched to create a suitable memory context.

Furthermore, multiple memory contexts can share the same memory arena. With cookmem::CachedArena, when one memory context is done, another context can reuse the segments allocated by the previous context. Thus, we can further avoid expensive calls to allocate large segments.

STL Allocator

There is one STL allocator implementation, cookmem::Allocator. It depends on a memory context provider to provide the cookmem::MemContext instance.

There are two memory context providers.

The scoped context helper temporarily overrides the context used by default-constructed allocators with the matching cookmem::TLSContextProvider. Declare it before containers that use the scoped context so the containers are destroyed before the scope ends.