Static memory allocator.
Original idea by Sergey Shevchuk (Nachos836);
Implementation by Taras Maliukh (Iipal);
Header-only library with malloc-like behavior for mapping\allocation memory on static buffer, so all work with memory mostly can be optimized and calculated at compile-time.
More details of everything documented in code.
Code logic based on this document, which explains everything about most common malloc-like allocator implementations. Details:
- Implemented using implicit bidirectional free-list aka Bidirectional Coalescing: Boundary Tags.
- Each allocation takes additional 16bytes in the static buffer for Boundary Tags info.
- In code, each Boundary Tag is described in the
__s_tag_tstructure
- In code, each Boundary Tag is described in the
- Each allocation aligned by 16bytes by default. (24 will align to 32)
- Each allocation will use Best Fit method to find a free block. Best Fit: Search the list, choose the best free block: fits, with the fewest bytes leftover.
- On
sfreecall implemented with Bidirectional Coalescing with preceding free blocks. - Optional nullability checks (
_Nonnulland_Nullable) withSALLOC_NULLABILITY. - All code formatted via
clang-format(version 12.0). - No dependency on any library, even on standard libc.
- NOTE: If you define
SALLOC_DEBUGbeforesalloc.hinclude then it's will include alsostdio.handsalloc_tracewill useprintf.
- NOTE: If you define
Originally it's written for
clangonly, because of its features.
All macroses, types or functions with prefixes:
__s_,__st_,__s2c,__sattr_,__salloc_or__sfree_are created only for internal-use purposes.