3 ms·
As some comments point out that this code might not be production ready, can anyone recommend other solutions that are able to manage a given block of memory? M
by felixguendling 8y ago
As some comments point out that this code might not be production ready, can anyone recommend other solutions that are able to manage a given block of memory? My understanding of libraries like jemalloc is that they are replacing malloc (using system calls brk and mmap [0]) but I can't hand it an already allocated block of memory to manage, right?
Something like
memory_manager m(some_buffer);
allocation a = m.allocate(512);
would be nice. :-)
[0] https://medium.com/iskakaushik/eli5-jemalloc-e9bd412abd70 https://medium.com/iskakaushik/eli5-jemalloc-e9bd412abd70
- lfy_google 8y agohttps://android.googlesource.com/platform/external/qemu/+/emu-master-dev/android/android-emu/android/base/SubAllocator.h https://android.googlesource.com/platform/external/qemu/+/em... https://android.googlesource.com/platform/external/qemu/+/emu-master-dev/android/android-emu/android/base/SubAllocator.cpp https://android.googlesource.com/platform/external/qemu/+/em... https://android.googlesource.com/platform/external/qemu/+/emu-master-dev/android/android-emu/android/base/address_space.h https://android.googlesource.com/platform/external/qemu/+/em... These 3 files should be a fairly self contained, minimal way to allocate into existing buffers. No attempt is made at thread safety though (we assume the user synchronizes that themselves)
- ksherlock 8y agoSQLite memory system 5: https://www.sqlite.org/src/artifact/9bf955937b07f8c3 https://www.sqlite.org/src/artifact/9bf955937b07f8c3
- dividuum 8y agoThis TLSF implementation should be able to do that: https://github.com/mattconte/tlsf https://github.com/mattconte/tlsf
- nuclx 8y agoFreeRTOS features sone nice and simple allocators on fixed buffers [0]. I have used heap4 to implement memory management for a fully portable test suite requiring malloc. Really any toy allocator would have done the job for that use-case, since performance wasn't critical, but heap4 was fairly easy to integrate. [0] https://www.freertos.org/a00111.html https://www.freertos.org/a00111.html
- davidtgoldblatt 8y agoDepending on what exactly you mean by "hand it a block of memory to manage", you can do this with jemalloc's extent hook functionality. Though that's meant for "I have some long-lived data structures, I want all their memory stored on hugepages" more than "I have this small-ish data structure, I want to batch its allocations together".