
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> ? Thanks. Steve. --------------------------------- Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more.

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. -- with best wishes, Alexander Vushkan

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

Michael Marcin <mmarcin@method-solutions.com> wrote: Alexander Vushkan wrote:
Hi Steve.
On 8/15/07, Steve Kettle wrote:
I have a question about the memory pool allocation that boost implements. Suppose we do the following: std::vector > v; for (int i = 0; i < 10; ++i) v.push_back(-1);
And the std::vector 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 > v; for (int i = 0; i < 10; ++i) v.push_back(-1);
std::vector > 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 ?
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 _______________________________________________ Basically what I am doing is I have an application the uses about 20 threads to do a heavy duty computation. Each thread is basically doing the same computation - just using different parameters to the computation but for the most part each thread does the same amount of work. It seems the heap is used mainly in two places in the computation - the first is inserting data in to a huge multimap< double, Foo > and the second is building vectors. I used the multimap< double, Foo, boost::fast_pool_allocator< std::pair< double, Foo > > ( forgive the syntax here ). This sped things up quite a bit. I tried using std::vector< int, boost::pool_allocator< int > > but this did not really help things. One more thing is I would like to try out each thread using its own heap but I have know idea how to do this - I don't know if boost allows for such a thing. I could somehow put in my own operator new and then look up the pool to use based on the id of the thread but this sounds like it would be pretty slow. Thanks. --------------------------------- Need a vacation? Get great deals to amazing places on Yahoo! Travel.
participants (3)
-
Alexander Vushkan
-
Michael Marcin
-
Steve Kettle