Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/philip-wernersbach/memory-pool-allocator
C memory allocator based on pools, thread safe.
https://github.com/philip-wernersbach/memory-pool-allocator
Last synced: 5 days ago
JSON representation
C memory allocator based on pools, thread safe.
- Host: GitHub
- URL: https://github.com/philip-wernersbach/memory-pool-allocator
- Owner: philip-wernersbach
- License: unlicense
- Created: 2014-01-04T22:43:09.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-05T23:47:14.000Z (almost 11 years ago)
- Last Synced: 2024-08-03T09:07:42.132Z (4 months ago)
- Language: C
- Size: 164 KB
- Stars: 14
- Watchers: 6
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pmpa - Phil's Memory Pool Allocator
=====================C memory allocator based on pools, thread safe.
Features
---------------------
* Simple & Fast
* Less than 200 lines of C code
* Pool-based allocation
* Automatically defragments the pool in a deterministic fashion, without the need for garbage collection
* Lockless, thread-safe design
* Each thread gets its own memory pool
* No limit on memory pool or allocation sizes
* Implements all C memory allocation functions
* Optional drop-in mode so that you don't have to change your code
* Comprehensive benchmark & test suites
* Permissively licensed: Dual-licensed under the Public Domain and the Unlicense
* Choose the one that you preferHow to Use
---------------------
**Regular Mode**1. Compile `pmpa.c` into your program.
2. Include `pmpa.h` in your program.
3. Define `ARCH_64BIT` or `ARCH_32BIT`, depending on your architecture.
4. Use `pmpa_init_thread()` in each thread that will use pmpa, **before** you allocate memory with pmpa.
* Example: If your program is going to allocate a maximum of 64kb of memory, use `pmpa_init_thread(65536)`.
* The actual allocatable memory will be slightly less than what's specified, due to pmpa using some memory for pool accounting.
5. Use the `pmpa_*` versions of the C memory allocation functions.
* Example: Use `pmpa_malloc()` where you would use `malloc()`, etc.
6. Use `pmpa_uninit_thread()` in each thread when the thread is done using pmpa.**Drop-in Mode**
1. Follow all of the steps in Regular Mode until step 5.
2. Define `PMPA_OVERRIDE_C_MEMORY_FUNCTIONS` in your program
* This define causes pmpa to override the standard C memory allocation functions with the `pmpa_*` ones.
3. Follow step 6.