
Alexander Vushkan wrote:
Hi Steve.
On 8/15/07, Steve Kettle <skettle2000@yahoo.com> wrote:
I have a question about the memory pool allocation that boost implements. Suppose we do the following: std::vector<int, boost::pool_allocator<int> > v; for (int i = 0; i < 10; ++i) v.push_back(-1);
And the std::vector<int> is implemented so that it starts out with reserved space of 1 and doubles space every time. So At the end of the above loop v will have size 10 and reserved size 16.
Does the boost allocator mean that there will memory arrays lieing around of size 1,2,4,8 that can be reused ?
Eg if you do this:
std::vector<int, boost::pool_allocator<int> > v; for (int i = 0; i < 10; ++i) v.push_back(-1);
std::vector<int, boost::pool_allocator<int> > v2; for (int i = 0; i < 8; ++i) v2.push_back(-1);
There will be no system call needed to get more memory - v2 will just reuse the memory in the pool_allocator<int> ?
No, it seems to me each allocator holds own piece.
Are you sure about that? IIRC the pool allocator is a singleton per size i.e. boost::singleton_pool< boost::pool_allocator_tag, sizeof(int) > - Michael Marcin