alloc
alloc copied to clipboard
Highly space and performance efficient C allocator
This is a custom memory allocator I wrote in C. Its features are:
-
Lack of loops, where every memory-related code path is
O(1). -
Lack of per-allocation metadata, increasing cache friendliness and decreasing memory footprint.
-
All allocations are by default aligned to the next or equal power of 2 of the size that is requested. [^2]
-
Thread-safe by default, with an option to disable it at compilation.
-
Decentralized, allowing for scalability and fragmentation resistance.
-
Simpler, faster, using less kernel time than all dlmalloc offsprings. [^1]
-
Completely encapsulated, with zero heap usage.
-
Customizable at compile-time (the defaults) as well as at runtime.
[^1]: 33-50% faster on Linux/MacOS, ~75% faster on Windows, but speed may vary between different environments and workloads. The kernel time difference used to be clearly visible back when time was used to measure the benchmark, but there have been issues with the command not working on some platforms in specific settings, so it was replaced with in-code time measuring that only takes real time into account.
[^2]: Zero cost for small allocations, then grows slightly as the allocation size grows, caps out at below a page size for large allocations (not per-allocation, but per-handle), which comparatively is rather little.
It supports Linux, MacOS, Windows (mingw/msys), 64bit and 32bit.
C
See this for more information.
Rust
See this for more information.
WebAssembly
By design (no heap usage), WebAssembly is not and never will be supported.
Docs
The first, older version of the code, had inline comments that you can still access here. Not much has changed.
Contributions
... are welcome. This is a very fresh, immature project. It could use more updates.