mjansson/rpmalloc logo

mjansson/rpmalloc

Free

Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C

FreeFree tier
Type
Open Source

About mjansson/rpmalloc

rpmalloc is a public domain, cross-platform, lock-free, thread-caching, 16-byte aligned memory allocator implemented in a single ~3300 line C source file. It is designed for high-performance multi-threaded applications and claims to outperform popular allocators like tcmalloc, hoard, and ptmalloc3 in throughput while maintaining low memory overhead. The allocator supports Windows, Linux, macOS, iOS, and Android, and can be easily ported to any platform with atomic operations and an mmap-style virtual memory API. It is available under the Unlicense or MIT license.

Key Features

Lock-free algorithms for high concurrency
Per-thread caching to reduce contention
16-byte natural alignment for all allocations
Cross-platform support (Windows, Linux, macOS, iOS, Android)
Single source file (~3300 lines) for easy integration
Public domain (Unlicense) or MIT licensed
Automatic initialization on first allocation
Customizable memory page mapping and page size

Pros & Cons

Pros
  • Faster than tcmalloc, hoard, ptmalloc3 in benchmarks
  • Low memory overhead from thread caches
  • Easy to integrate (single .c and .h file)
  • Permissive dual-license (public domain or MIT)
  • Automatic initialization with default configuration
  • Actively maintained with 2.5k GitHub stars
Cons
  • Limited to platforms with mmap-style virtual memory API
  • Performance may vary depending on allocation patterns
  • Documentation and comments could be more extensive
  • Not suitable for non-C/C++ environments without a C wrapper

Best For

General-purpose memory allocation in C/C++ programsHigh-performance server and game enginesMulti-threaded applications requiring low allocation latencyProjects seeking a drop-in replacement for malloc/freeEmbedded systems with limited memory overhead constraints

FAQ

Do I need to explicitly initialize rpmalloc?
No, the allocator is initialized automatically on the first allocation request with default configuration. However, if you want to provide a custom memory interface or configuration, you must call rpmalloc_initialize or rpmalloc_initialize_config before any other allocator call.
Is rpmalloc thread-safe?
Yes, it is designed as a lock-free thread-caching allocator, making it safe for concurrent use across multiple threads without contention.
What license does rpmalloc use?
rpmalloc is dual-licensed under the Unlicense (public domain) and the MIT license. You may choose either.
Which platforms are supported?
The allocator currently supports Windows, Linux, macOS, iOS, and Android. It can be ported to any platform with atomic operations and an mmap-style virtual memory API.