|
Boost : |
From: Alexander Vushkan (alexander.vushkan_at_[hidden])
Date: 2007-08-15 05:17:08
Hi Steve.
On 8/15/07, Steve Kettle <skettle2000_at_[hidden]> 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.
-- with best wishes, Alexander Vushkan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk