
2 Mar
2009
2 Mar
'09
5:56 p.m.
Thorsten Ottosen:
Peter Dimov skrev: ...
for x in w if pred(x) v.push_back(x)
The typical number of elements satisfying pred may be ~7.1, so making v have a stack capacity of 8 will eliminate a heap allocation and will be a big win. But you can't determine the maximum capacity in advance.
Is it not |w|?
Yes, it technically is bounded by |w|. But using |w| as the capacity of v defeats the purpose of the optimization, which is to avoid allocating storage for |w| elements (typically on the heap).