Home

Awesome

smmalloc

Actions Status Build status codecov MIT

About

smmalloc is a fast and efficient "proxy" allocator designed to handle many small allocations/deallocations in heavy multithreaded scenarios. The allocator created for using in applications where the performance is critical such as video games. Designed to speed up the typical memory allocation pattern in C++ such as many small allocations and deletions. This is a proxy allocator means that smmalloc handles only specific allocation sizes and pass-through all other allocations to generic heap allocator.

Commercial games using smmalloc

Features

Performance

Here is an example of performance comparison for several different allocators.
Platform: Windows 10, Intel Core i7-2600

Threads#1#2#3#4#5
crt2385386515410410159936551412460714636381
rpmalloc7586641452689298526062154605890938706739
hoard6592203246605339428745163440461827629651
ltalloc6252596552315981416349923355772627333887
smmalloc9261538470584046663523244708750138303161
smmalloc (no thread cache)49295774259914651134280986152166455889
dlmalloc + mutex313133945858632382463633546722135141
dlmalloc1063040790000

Performance comparison

Here is an example of performance comparison for several different allocators.
Platform: Playstation 4

Threads#1#2#3#4
mspace4741379956729457264366920
crt4444444853385419009332095
ltalloc28571429252906981924817414683637
smmalloc36065574293333332520241221868691
smmalloc (no thread cache)22916667852713256318154198497
dlmalloc + mutex80586081848623579845564604
dlmalloc35483871000

Performance comparison

Usage

_sm_allocator_create - create allocator instance
_sm_allocator_destroy - destroy allocator instance
_sm_allocator_thread_cache_create - create thread cache for current thread
_sm_allocator_thread_cache_destroy - destroy thread cache for current thread
_sm_malloc - allocate aligned memory block
_sm_free - free memory block
_sm_realloc - reallocate memory block
_sm_msize - get usable memory size

Tiny code example


// create allocator to handle 16, 32, 48 and 64 allocations (4 buckets, 16Mb each) 
sm_allocator space = _sm_allocator_create(4, (16 * 1024 * 1024));

// allocate 19 bytes with 16 bytes alignment
void* p = _sm_malloc(space, 19, 16);

// free memory
_sm_free(space, p)

// destroy allocator
_sm_allocator_destroy(space);