This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: too much copy in map
- To: Levente Farkas <!spam-lfarkas at mindmaker dot hu>
- Subject: Re: too much copy in map
- From: "Jeremy G. Siek" <jsiek at cthulhu dot engr dot sgi dot com>
- Date: Fri, 10 Mar 2000 00:43:11 -0800
- CC: "Jeremy G. Siek" <jsiek at cthulhu dot engr dot sgi dot com>, stl at sgi dot com, libstdc++ at sourceware dot cygnus dot com
- Organization: University of Notre Dame
- References: <38C801AC.DF18D6A@engr.sgi.com> <38C8B265.7FDFC083@mindmaker.hu>
Well, I'm not sure what I'm about to say will work for your
real program, but here's what you can do for this toy example:
Map::value_type v;
v.first = 1;
m.insert(v);
However, I'm not sure why you are worried about 1 extra copy.
For small objects, the extra copy gets optimized
away with a good compiler. For large objects... well you
probably shouldn't put a large object directly into the map... instead
store pointers in the map and define a custom compare operator.
Levente Farkas wrote:
>
> ok. then the proper question:
> why is not there a way to insert something into a map with just
> ONE copy contructor call ?
> yes you can said that this's the standard, but if there be an
> insert(const key_type&, const mapped_type&) or at least
> operator[const key_type&] could have implement in a way to call
> just one copy constructor.
>
> > The first copy is even before you get to the insert().
> > The "Map::value_type(1,A())" creates a pair, *copying* A()
> > into the pair's data member. So there is only one copy
> > inside insert(), and that is necessary.
--
------------------------------------------------------------------------
Jeremy Siek email: jsiek@engr.sgi.com
Ph.D. Candidate cell-phone: (415) 377-5814
Univ. of Notre Dame phone: (650) 933-8724
C++ Library & Compiler Group fax: (650) 932-0127
Silicon Graphics Inc. www: http://www.lsc.nd.edu/~jsiek/
------------------------------------------------------------------------