Allocators

K

Karl Napf

Hi, I'm wondering why allocators only have a "copy-construct" method,
but no method for default construction. For large objects that shall
be initialized using the default constructor, this seems to be quite
inefficient since one first has to create a temporary object which is
then copied to the allocated space. Any ideas how to avoid this?
Thanks and regards, Karl.
 
J

Juha Nieminen

Pete Becker said:
Allocators do have a default constructor.

I think he meant that allocators don't offer a way to default-construct
an allocated object (rather than allocators not having a default
constructor).
 
K

Karl Napf

  I think he meant that allocators don't offer a way to default-construct
an allocated object (rather than allocators not having a default
constructor).

Right, that's what I meant :)
 
H

Howard Hinnant

Right, that's what I meant :)

This will be corrected in C++0X. Allocators will be able to construct
objects using any argument list (including an empty one), and the
allocator author doesn't even have to implement it (reference
[allocator.traits.members], it's pretty cool work by Pablo Halpern).

-Howard
 
J

James Kanze

I'm wondering why allocators only have a "copy-construct" method,
but no method for default construction.

So that you can have collections of objects which don't support
default construction.
For large objects that shall be initialized using the default
constructor, this seems to be quite inefficient since one
first has to create a temporary object which is then copied to
the allocated space.

The way the STL is designed supposes efficient copy anyway. If
you want objects to be efficiently stored in STL containers,
provide them with efficient copy. (Add a level of indirection,
etc.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top