Recently i have been looking for a pool/allocator mechanism. Boost Pool seems to provide the solution, but there is still things, which it have not been able to deduce from the documentation.
What need to be allocated
- Several small classes (~30 chars)
- std::map (i want to ensure it do not perform dynamic allocator by itself)
- allocation within pugi::xml
- std::strings
How to control of address space for allocation (or just amount)
The object_pool seem the to provide a good way for allocating need 1) However it would like to set a fixed size for the allocator to use. By default it grabs memory be ifself. If possible i would like to give it the address space it can play within.
char * mem_for_class[1024*1024];
boost::object_pool<my_class,mem_for_class> q;
or:
const int max_no_objs=1024;
boost::object_pool<my_class,max_no_objs> q;
Although the UserAllocator is available in Boost::Pool; it seem to defeat the point. I am afraid the control needed would make it too inefficient... and it would be better to start from scratch.
It it possible to set a fixed area for pool_allocator ?
The question is a bit similar to the first. Do boost pool provide any way of limiting how much / where there is allocated memory when giving boost::pool_allocator to a std-type-class (e.g. map)
My scenario
Embedded linux programming. The system must keep running for..ever. So we can not risk any memory segmentation. Currently i mostly either static allocation (stack), but also a few raw "new"s. I would like an allocation scheme that ensure i use the same memory area each time the program loops. Speed /space is important, but safety is still top priority.
I hope StackOverflow is the place to ask. I tried contacting the author of Boost::Pool "Stephen" without luck. I have not found any Boost-specific forum.
See Question&Answers more detail:os