A pure C (though C++ compatible) allocator that works with mmap allowing you to retain data semi-transparently between process runs. This allows you to "run" within a persistent space without the typical overheads of file I/O, and for your memory structures to be recovered, either to continue running or to "archeologically" retrieve data from before a crash (depending on your needs and architecture).
- thread safe && lock free - no blocking, no spin locks, just pure atomics
- malloc,- freeand- reallocimplementations
- archeology / forensic capabilities - rewrite pointers from previous memory spaces using persistent_ptr
- identifiable / tagged allocations - persistent_malloc_rootallows "root" allocations to be tagged for later retrieval (between process runs)
- some C++ functionality - smart/fancy pointer named PersistentPtr<*>automatically keeps track of itsallocator_spaceeven between address changes (restarts)- PersistentPtris header-only and- nostdlibcompatible
 
- Fixed size - the allocator currently works strictly within a single fixed region and will not attempt to acquire more memory
- No callocequivilent - if you want clean memory, usememsetafterpersistent_malloc
- Non-optimal realloc - persistent_reallocwill not attempt to merge contiguous blocks of memory to avoidmemcpy
- PersistentPtrcannot be made atomic (yet) - this will be added when I have time
- No C++ STL Allocator(yet)
- Requires 64bit lock-free atomics to be available
Care needs to be taken when using raw pointers within the space, persistent_ptr can be used to archeologically recover raw pointers from a previous run, but you should treat these spaces as read only. persistent_ptr works by adjusting the pointer based on the "old" and "new" memory address of the persistent space (new_raw_ptr = old_raw_ptr - &old_raw + &new_space) but since there is only a single slot for the origin to be stored we can only adjust from a single "old" space into our "new" space. For more flexibility C code can make use of the persistent_offset_t typealias along with the ptr_to_persistent_offset and persistent_persistent_offset_to_ptr macros to convert to and from raw pointers.
For C++ code there is a persistent_mem::PersistentPtr template class which can be treated like other fancy pointers, but remain internally consistent if they are properly initialised (they must be passed a allocator_space_t* at least once).