akmalloc
is a composite allocator, combining slabs and coalescing allocators.
It uses a static ak_malloc_state
.
All the exported APIs are based on ak_malloc_state
.
It uses an array of slabs of sizes from 8B to 256B, an array of coalescing allocators ranging in size from 768B to 1MB and directly uses OS calls beyond that size.
It handles multi threading by having a lock per slab or coalescing allocator, or OS calls. Multiple threads that allocate or free a size in a different size category do not contend with each other.
By default shared and static libraries have a thread safe malloc and free.
Every allocation has a 8B header which contains a distinct bit mask allowing the allocator to classify it.
akmalloc
can be built as a shared library, static library, or included directly as part of your source code.
To include this akmalloc directly, simply define AKMALLOC_INCLUDE_ONLY
before including the malloc.h
file.
To build a static library, define AKMALLOC_LINK_STATIC
and you may have to change AKMALLOC_EXPORT
.
To build a shared library, define AKMALLOC_BUILD
when building the library, and set AKMALLOC_EXPORT
to be the right visibility symbol for your compiler/system i.e., __declspec(dllexport)
on Windows/MSVC and __attribute__((__visibility__("default")))
on Linux/Mac.
When including the header for the shared library, ensure AKMALLOC_EXPORT
is defined correctly for the import (__declspec(dllimport)
on Windows/MSVC and on Linux/Mac).
akmalloc
The following defines are available for use while building (or including if your build is only directly including the header files). They are marked as controlling one or more options.
It is better to define these before including any akmalloc
header files.