Boost logo

Boost :

Subject: Re: [boost] [devector] optimum growing/insertion policy
From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2017-10-16 17:45:58


Den 16-10-2017 kl. 19:18 skrev Thorsten Ottosen via Boost:

> I do want to focus on simple properties from a user's perspective. Some
> cases to consider:
>
> # case 1: push_back from empty state
> ------------------------------------
>
>   vector<int> v;
>   v.reserve( N );
>
> This guarantees N pushes without exceptions and without reallocation.
>
>
> # case 2: push_back from unknown state
> --------------------------------------
>
>   vector<int> v;
>   ...
>   v.reserve( v.size() + N );
>
> This guarantees N pushes without exceptions and without reallocation.

A note: this is why I absolutely loathe reserve() compared to a function
called

   v.anticipate( N )

which would work equally well in both cases.

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk