Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Allocators

Reply
Thread Tools

Allocators

 
 
Karl Napf
Guest
Posts: n/a
 
      03-25-2010
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.
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      03-26-2010
Pete Becker <(E-Mail Removed)> wrote:
> Karl Napf wrote:
>> Hi, I'm wondering why allocators only have a "copy-construct" method,
>> but no method for default construction.

>
> 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).
 
Reply With Quote
 
 
 
 
Karl Napf
Guest
Posts: n/a
 
      03-26-2010
On 26 Mrz., 07:46, Juha Nieminen <(E-Mail Removed)> wrote:
> Pete Becker <(E-Mail Removed)> wrote:
> > Karl Napf wrote:
> >> Hi, I'm wondering why allocators only have a "copy-construct" method,
> >> but no method for default construction.

>
> > 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).


Right, that's what I meant
 
Reply With Quote
 
Howard Hinnant
Guest
Posts: n/a
 
      03-27-2010
On Mar 26, 3:52*am, Karl Napf <(E-Mail Removed)> wrote:
> On 26 Mrz., 07:46, Juha Nieminen <(E-Mail Removed)> wrote:
>
> > Pete Becker <(E-Mail Removed)> wrote:
> > > Karl Napf wrote:
> > >> Hi, I'm wondering why allocators only have a "copy-construct" method,
> > >> but no method for default construction.

>
> > > 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).

>
> 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
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      03-28-2010
On Mar 25, 9:20 pm, Karl Napf <(E-Mail Removed)> wrote:
> 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.)

--
James Kanze
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Containers & Allocators Ares Lagae C++ 6 02-21-2005 11:46 AM
Help with STL allocators mar00ned C++ 6 09-24-2004 06:16 PM
operator= in allocators Mark A. Gibbs C++ 9 04-04-2004 02:54 PM
Re: allocators...exceptions...new/delete Richard Smith C++ 20 07-21-2003 05:38 AM
Re: allocators...exceptions...new/delete Ross Ridge C++ 2 07-07-2003 08:07 AM



Advertisments