Boost logo

Boost :

Subject: Re: [boost] [unordered] please don't allocate memory in the default constructor
From: Daniel James (daniel_james_at_[hidden])
Date: 2009-08-22 09:53:40

2009/7/14 Thorsten Ottosen <thorsten.ottosen_at_[hidden]>:
> I think this a really bad idea to allocate in the default construtor. The
> user can always call rehash() on the empty container, just like when we call
> reserve() for vector.

The unordered containers are specified in a way that suggests memory
will always be allocated for the buckets - and IIRC all the publicly
available implementations do that.

Although it is possible to avoid the allocation when constructing
empty containers (I think a while ago I said it wasn't, but I've
worked out how since). A check needs to be added to pretty much every
method to make sure that the buckets have been allocated which might
have a performance hit and increase the executable size.

The implementation also has to make sure the end iterator is valid for
empty containers. Currently the end iterator points to the sentinel
bucket so that the iterators don't need to be able to tell when
they've reached the end of the buckets, instead I'd have to use null
pointers for the end iterators and add a mechanism to detect when the
end of the buckets is reached - making iteration a bit slower. I'm not
sure if the trade off is worth it.


Boost list run by bdawes at, gregod at, cpdaniel at, john at