Re: [Flightgear-devel] vector.push_back() and the d'tor
On Tue, Apr 06, 2004 at 09:03:51PM -0500, Jon Berndt wrote: I'm not positive, but it seems (roughly) like a vector push_back() operation causes the d'tor to be called after the first element is stored. To me, this Yes, if capacity() changes on a resizing operation (like push_back()), the elements need to be moved to a new location, like a realloc() would do in C. This will happen every so often, but so that on average, push_back() finishes in constant time. If you know already on construction time how large your vector will be, you should always call reserve(). HTH -Gerhard -- Gerhard Wesp o o Tel.: +41 (0) 43 5347636 Bachtobelstrasse 56 | http://www.cosy.sbg.ac.at/~gwesp/ CH-8045 Zuerich \_/ See homepage for email address! ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] vector.push_back() and the d'tor
Jon Berndt wrote: I'm not positive, but it seems (roughly) like a vector push_back() operation causes the d'tor to be called after the first element is stored. To me, this seems to say that the push_back() operation copies the existing stored element[s] to a new location (resizing the container) and destroys the old copy of the object stored in the vector. I'm looking into this in Stroustrup, but if anyone has any insights to share on this I'd be interested to hear them. If you have vectorMyClass list; then MyClass listItem; list.push_back(listItem); will add a copy to the list. To avoid that, use vectorMyClass * list; To avoid surprises, it's always a good idea to declare a private copy constructor and assignment operator by default if your class doesn't need a public one. All the best, David ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
[Flightgear-devel] vector.push_back() and the d'tor
I'm not positive, but it seems (roughly) like a vector push_back() operation causes the d'tor to be called after the first element is stored. To me, this seems to say that the push_back() operation copies the existing stored element[s] to a new location (resizing the container) and destroys the old copy of the object stored in the vector. I'm looking into this in Stroustrup, but if anyone has any insights to share on this I'd be interested to hear them. Jon ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
RE: [Flightgear-devel] vector.push_back() and the d'tor
I'm not positive, but it seems (roughly) like a vector push_back() operation causes the d'tor to be called after the first element is stored. To me, this seems to say that the push_back() operation copies the existing stored element[s] to a new location (resizing the container) and destroys the old copy of the object stored in the vector. I'm looking into this in Stroustrup, but if anyone has any insights to share on this I'd be interested to hear them. Jon Looks like indeed that is the case, though where possible reserve() may help me out. Jon ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel