Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!newsfeed.utanet.at!newscore.univie.ac.at!newsfeed01.chello.at!newsfeed02.chello.at!news.hispeed.ch.POSTED!not-for-mail Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes Newsgroups: comp.lang.c++ Subject: Re: STL vector References: <4ec2cbd5$0$6638$9b4e6d93@newsspool2.arcor-online.net> Date: Wed, 16 Nov 2011 08:55:00 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable From: "Peter Liedermann" Message-ID: User-Agent: Opera Mail/11.52 (Win32) X-Complaints-To: abuse@hispeed.ch Organization: hispeed.ch Lines: 80 NNTP-Posting-Host: 80.219.145.247 (80.219.145.247) NNTP-Posting-Date: Wed, 16 Nov 2011 08:57:03 +0100 X-Trace: a00464ec36ccff57e345215357 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:11503 On Tue, 15 Nov 2011 21:30:14 +0100, Marcel M=FCller = wrote: > On 15.11.2011 20:50, Peter Liedermann wrote: >> Let "Jumbo" be the name of a class whose instances consume substantia= l >> storage. >> >> A vector of typically 1000 such Jumbo-instances is needed. It must be= >> sorted by a simple int criterium, but not often. >> >> Is there a substantial performance difference between vector = and >> vector , provided that everything else is adapted accordingl= y? >> Is there a difference at all? > > In general you need to copy the Jumbo objects to put them into the = > vector. The copy constructor of Jumbo might be quite expensive if it i= s = > not a POD like type. Is that what you want? I think this is the key to my question: Jumbo * is a POD type and Jumbo = = itself is clearly not. For illustration of the term POD, I found http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html useful. > You should also think about the (re)allocations of vector. A = > vector will in general allocate more slots than needed. If Jumbo is = > large, then this might be a reasonable amount of memory. Furthermore, = a = > vector might not start with it's final size. So there are some = > reallocations necessary before the vector has it's final size. These = > reallocations copy the entire content. Since I am now determined to use Jumbo * and can exactly predict the = number of slots, this is not relevant to my situation although generally= = good to know. Question: If I would use vector instead and the = Jumbo objects were of varying length and I would start the vector with a= ll = NUL entries, could I then get the reallocation/copy problem mentioned? > Personally I would prefer vector> or some other = > smart pointer over vector, because it answers the ownership = > question more clearly. However, details depend on your application. > Thank you for this suggestion. I will practice the use of the mentioned= = smart pointers at a good opportunity. At the present project, though, I= = will use vector because ownership is out opf qustion and it is = = not the time to risk anything new. Thanx, Peter