From -5950394451014254025
X-Google-Thread: f78e5,4ae4d1cd1dd2d66c
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.68.232.169 with SMTP id tp9mr15414833pbc.6.1332642481893;
        Sat, 24 Mar 2012 19:28:01 -0700 (PDT)
MIME-Version: 1.0
Path: kz5ni30512pbc.0!nntp.google.com!news1.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!news.albasani.net!.POSTED!not-for-mail
From: Francis Glassborow <francis.glassborow@btinternet.com>
Newsgroups: comp.std.c++
Subject: Re: Request =?ISO-8859-1?Q?f=F6r_std=3A=3Avector_and_possi?=
 =?ISO-8859-1?Q?bly_others=3A_minimal_initalization?=
Date: Sat, 24 Mar 2012 19:28:00 -0700 (PDT)
Organization: unknown
Lines: 35
Sender: std-cpp-request@vandevoorde.com
Approved: james.dennett@gmail.com
Message-ID: <J8-dnSYJv8QjLvDSnZ2dnUVZ7sidnZ2d@bt.com>
References: <abf103e0-7005-47b4-9888-af946353a525@v22g2000vby.googlegroups.com>
 <vtidnTDJTMF2M_TSnZ2dnUVZ7sOdnZ2d@bt.com>
 <2bd4117e-d3cb-436f-b1a9-f08971dbdce2@h5g2000vbx.googlegroups.com>
NNTP-Posting-Host: FVvJHKi81nwleac1A48ZIqH5Uf3cjSPpWclLKSlbpgA=
X-Trace: news.albasani.net +KUT9yz06I9f0RpkYLa99N67PsB6YZENqIYUmu6V+WEnVMUl7TAiWDCCiRU/XIRLEXk0ktwO4dGfbx2v8+115w==
X-Complaints-To: abuse@albasani.net
NNTP-Posting-Date: Sun, 25 Mar 2012 02:28:01 +0000 (UTC)
X-Mailer: Perl5 Mail::Internet v2.05
X-Submission-Address: std-cpp-submit@vandevoorde.com
Cancel-Lock: sha1:PXFVepq0ldsm/oudjud2doaMPgA=
X-Original-Date: Sat, 24 Mar 2012 11:44:40 +0000
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 24/03/2012 00:09, henrikv wrote:
>
> On 21 mar, 19:35, Francis
> Glassborow<francis.glassbo...@btinternet.com>   wrote:
>>
>>  Isn't that what reserve() is for?
>
>
> What I want to do is to allocate a vector for results calculated in a
> parallel loop. Reserve+push_back will not work, since it's not
> guaranteed that results will be stored in a predictable order. You
> might even get multiple push_back's executed at once, which I suspect
> isn't a great idea.
>

If multiple simultaneous push_backs are possible then you will have to
deal with the problem of multiple threads. How are you going to
determine which element of the vector will be assigned to each
result?. And how will you manage to store results computed
concurrently in a predictable order.

Those issues can be dealt with, but being concerned about the cost of
default initialising your vector seems to be unnecessary.

Just make sure that the objects you are creating have a default
constructor that does nothing.
>
>


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]


