Boost logo

Boost :

From: Steve Kettle (skettle2000_at_[hidden])
Date: 2007-08-15 15:46:06


Michael Marcin <mmarcin_at_[hidden]> 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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk