
Daniel James skrev:
2009/7/14 Thorsten Ottosen <thorsten.ottosen@dezide.com>:
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.
don't the implementation already check when it needs to rehash the container? Can't that check be reused for growing from an empty container just like with vector?
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.
Is it noticable slower? -Thorsten