Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11517
| From | yatremblay@bel1lin202.(none) (Yannick Tremblay) |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: STL vector |
| Date | 2011-11-16 16:54 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <ja0pre$3i1$1@dont-email.me> (permalink) |
| References | <op.v4z6q8m5vc68pg@hp2011.workgroup> <4ec2cbd5$0$6638$9b4e6d93@newsspool2.arcor-online.net> <op.v4039yoivc68pg@hp2011.workgroup> |
In article <op.v4039yoivc68pg@hp2011.workgroup>,
Peter Liedermann <peter09876@hispeed.ch> wrote:
>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?
Typically Jumbo should be more like:
class Jumbo
{
public:
Jumbo();
// etc
private:
data * m_data;
}
So the "size" of Jumbo would not be sizeof(Jumbo) and Jumbo objects
containing containing varying amount of data would all present the
same sizeof(aJumboOject).
for such a class, as mentionned elsewhere, a very efficient swap()
function could be implemented by simply swapping the internal
pointers.
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