Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11503
| 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 | <op.v4z6q8m5vc68pg@hp2011.workgroup> <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" <peter09876@hispeed.ch> |
| Message-ID | <op.v4039yoivc68pg@hp2011.workgroup> (permalink) |
| 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 |
Show key headers only | View raw
On Tue, 15 Nov 2011 21:30:14 +0100, Marcel Müller <news.5.maazl@spamgourmet.com> wrote: > On 15.11.2011 20:50, Peter Liedermann wrote: >> Let "Jumbo" be the name of a class whose instances consume substantial >> 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 <Jumbo> and >> vector <Jumbo *>, provided that everything else is adapted accordingly? >> 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 is > 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<Jumbo>. 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 <Jumbo> instead and the Jumbo objects were of varying length and I would start the vector with all NUL entries, could I then get the reallocation/copy problem mentioned? > Personally I would prefer vector<intrusive_ptr<Jumbo>> or some other > smart pointer over vector<Jumbo*>, 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 <Jumbo*> because ownership is out opf qustion and it is not the time to risk anything new. Thanx, Peter
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
STL vector "Peter Liedermann" <peter09876@hispeed.ch> - 2011-11-15 20:50 +0100
Re: STL vector Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-11-15 21:30 +0100
Re: STL vector Leigh Johnston <leigh@i42.co.uk> - 2011-11-15 21:13 +0000
Re: STL vector Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-11-15 22:46 +0100
Re: STL vector Leigh Johnston <leigh@i42.co.uk> - 2011-11-15 22:02 +0000
Re: STL vector / Heap fragmentation "Peter Liedermann" <peter09876@hispeed.ch> - 2011-11-16 09:02 +0100
Re: STL vector / Heap fragmentation Goran <goran.pusic@gmail.com> - 2011-11-16 00:39 -0800
Re: STL vector / Heap fragmentation "Peter Liedermann" <peter09876@hispeed.ch> - 2011-11-16 10:58 +0100
Re: STL vector / Heap fragmentation Goran <goran.pusic@gmail.com> - 2011-11-16 04:12 -0800
Re: STL vector "Peter Liedermann" <peter09876@hispeed.ch> - 2011-11-16 08:55 +0100
Re: STL vector yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-11-16 16:54 +0000
Re: STL vector Joe Gottman <josephgottman@comcast.net> - 2011-11-16 18:22 -0500
Re: STL vector Joe Gottman <josephgottman@comcast.net> - 2011-11-15 21:59 -0500
Re: STL vector "Peter Liedermann" <peter09876@hispeed.ch> - 2011-11-16 08:58 +0100
Re: STL vector Werner <werasm@gmail.com> - 2011-11-16 05:53 -0800
Re: STL vector Leigh Johnston <leigh@i42.co.uk> - 2011-11-16 14:02 +0000
Re: STL vector Leigh Johnston <leigh@i42.co.uk> - 2011-11-16 14:05 +0000
Re: STL vector "Peter Liedermann" <peter09876@hispeed.ch> - 2011-11-17 16:45 +0100
Re: STL vector Leigh Johnston <leigh@i42.co.uk> - 2011-11-17 16:19 +0000
Re: STL vector Joshua Maurice <joshuamaurice@gmail.com> - 2011-11-17 15:19 -0800
csiph-web