Need urgent help >> How to Handle Fragmentation in Boost's managed_shared_memory
I am using Boost::managed_shared_memory for my project. For allocate and deallocate we are using boost APIs as show in below example: shm_controller.reset(new boost::interprocess::managed_shared_memory( boost::interprocess::open_or_create, shmName, size));void * addr = shm_controller->allocate(size) ; shm_controller ->deallocate(addr); For this I have two question: 1) How can i handle fragmentation in this ? We are doing very frequent allocation and release. 2) What kind of allocation we are using in boost (slab, slub, slob) ? First question is very important for me. Please let me know if you want more info on any of these. Thanks, sharmavijay1991@gmail.com
On 08/17/17 19:22, vijay sharma via Boost wrote:
I am using Boost::managed_shared_memory for my project. For allocate and deallocate we are using boost APIs as show in below example:
shm_controller.reset(new boost::interprocess::managed_shared_memory( boost::interprocess::open_or_create, shmName, size));void * addr = shm_controller->allocate(size) ; shm_controller ->deallocate(addr);
For this I have two question:
1) How can i handle fragmentation in this ? We are doing very frequent allocation and release.
I don't think there are any built-in methods to defragment shared memory in Boost.Interprocess. You could probably implement something yourself by iterating over the allocated objects and copying them to another segment. I haven't done this and not sure if this is possible or how difficult it is.
2) What kind of allocation we are using in boost (slab, slub, slob) ?
It depends on what allocation algorithm you're using. Boost.Interprocess provides rbtree_best_fit (rb-tree based) and simple_seq_fit (linked list based). http://www.boost.org/doc/libs/1_64_0/doc/html/interprocess/memory_algorithms... managed_shared_memory uses rbtree_best_fit.
On 17/08/2017 19:05, Andrey Semashev via Boost wrote:
On 08/17/17 19:22, vijay sharma via Boost wrote:
I am using Boost::managed_shared_memory for my project. For allocate and deallocate we are using boost APIs as show in below example:
shm_controller.reset(new boost::interprocess::managed_shared_memory( boost::interprocess::open_or_create, shmName, size));void * addr = shm_controller->allocate(size) ; shm_controller ->deallocate(addr);
For this I have two question:
1) How can i handle fragmentation in this ? We are doing very frequent allocation and release.
If those allocation are due to node-based containers, then a pool allocator might help. Otherwise, you need to transfer all objects to a new segment so that all memory is allocated nearly contiguously. Ion
participants (3)
-
Andrey Semashev
-
Ion GaztaƱaga
-
vijay sharma