Subject: Re: [boost] [unordered] please don't allocate memory in the default constructor
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-09-10 11:46:53
Daniel James skrev:
> 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.
I thought a little about this. Do you think it would be possible to
add a constructor like
boost::unordered_xxx container( boost::dont_allocate_memory_tag() );
The postcondition for this constructor should only guarantee that
- the object is swappable
- the object is destructible
- the object is assignable
- the object is copyable
Calling anything else should result in undefined behavior.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk