[Development] Question about QCoreApplicationData::*_libpaths

Matthew Woehlke mwoehlke.floss at gmail.com
Thu Jan 21 18:10:21 CET 2016


On 2016-01-20 23:44, Kevin Kofler wrote:
> Almost all my containers grow with allocations. How should I know in advance 
> how much memory to reserve? It'd just waste an arbitrary amount of memory 
> and then still end up reallocating because it'll inevitably be exceeded at 
> some point. Variable-size containers are variable-size for a reason.
> 
> I consider reserve() to be a technical detail and a micro-optimization I 
> really should not have to bother with in 99+% of the cases.

99% is almost certainly an exaggeration.

There are three categories of containers:
- size is constant and known at compile time
- size is constant and known at run time
- size is variable (e.g. based on user actions)

There are quite a few instances of the second category. For example, in
reading a PLY file, the number of points and faces is (usually) known as
soon as the header is read. Obviously, these depend on what file is
being read, so the size is not a *compile* time constant, but it is
known prior to filling the container, and is for the most part constant.
Cases like these (or filling one container based on the contents of
another) are where reserve() is extremely helpful, and most certainly
more than "a technical detail and micro-optimization".

That's not to say that there aren't *also* instances of the third.

(And, yes, pedantically, in reality it is more like a continuum than
three distinct categories.)

-- 
Matthew




More information about the Development mailing list