Boost logo

Boost Users :

Subject: Re: [Boost-users] [Assign] reservation and insert efficiency
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2010-07-05 09:08:34


John Dlugosz skrev:
> Does the initialization form I showed earlier, e.g.
>
> std::vector<record_type> newvec= list_of().range(RecVec.begin(),db).range(newdata).range(de,RecVec.end());
>
> know to get the total length first, or will it keep re-allocating storage with each underlying insertion? That is, do I get a performance benifit from manually doing:
>
> std::vector<record_type> newvec;
> newvec.reserve (... add up the sizes of my three ranges ...)
> newvec += range(RecVec.begin(),db).range(newdata).range(de,RecVec.end());
>
> Hmm, I'm sure the last line would be somewhat different.
> Anyway, do I need to reserve first, or will it be reasonably smart about that?

list_of() is not particularly fast: it uses a deque to store the
elements that are being inserted. If you are into speed, look at
ref_list_of/cref_list_of (which is very fast), or wait till the new
version arrives with new utilities.

HTH

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net