I was trying to understand the strategy of boost::pool chunks pre-allocation.I read this and also this boost doc,but it is still not clear for me if it is possible to request a specific initial number of pre-allocated chunks when the pool is instantiated.When I say "chunk" I mean chunk = sizeof(SomeType) For example,I did this test:
Foo.h
class Foo
{
public:
typedef MAllocator<float> FloatPoolAllocator;
typedef std::shared_ptr<boost::pool<> > FloatPoolSP;
static FloatPoolSP _floatPoolSP;
static FloatPoolAllocator _floatAllocator;
std::vector<float, FloatPoolAllocator> data1;
std::vector<float, FloatPoolAllocator> data2;
std::vector<float, FloatPoolAllocator> data3;
};
Foo.cpp
std::shared_ptr<boost::pool<> > Foo::_floatPoolSP = std::shared_ptr<boost::pool<> >(new boost::pool<>(sizeof(uint8_t), 65536));
MAllocator<float> Foo::_floatAllocator = MAllocator<float>(_floatPoolSP);
Foo::Foo()
{
data1 = std::vector<float, FloatPoolAllocator>(_floatAllocator);
data2 = std::vector<float, FloatPoolAllocator>(_floatAllocator);
data3 = std::vector<float, FloatPoolAllocator>(_floatAllocator);
}
Now,I am expecting my process memory to be at least twice the size of the specified boost::pool size because I allocate also other pools in different places with chunk sizes varying from 4 to 16 mb.This pool alone is 64 mb and looking into Windows Task Manager(not the best tool to investigate the memory...) I see the total memory consumption is around 78 mb.And it leads me to think that boost::pool doesn't allocate a block size of 65536,at least not at the first time.Is that true?And if it is,does it mean I need to wrap my own pool to allow such a functionality?Because I haven't found anything inside the pool that would allow another way of doing it.
PS: And if I remove the pools I see almost the same amount of memory used by the process which again probably means that boost::pool allocates a very small size of chunks.