[Development] Important recent changes in QList/QString/QByteArray
ville.voutilainen at gmail.com
Thu Sep 10 15:38:55 CEST 2020
On Thu, 10 Sep 2020 at 16:04, Andrei Golubev <andrei.golubev at qt.io> wrote:
> Should I expect to do a reserve call with a *smaller* value than my
> current size is before removing elements from
> a container, in order to set a "target size"? For any standard
> container, such a reserve is a complete noop because
> it can't be responded to by shrinking a capacity lower than the size,
> but with QList it apparently records a preferred size?
> No. If the value passed to reserve is smaller than capacity, we do not shrink*.
> For any passed value, we set a specific flag that the capacity is reserved. There is no notion of "target size" and "target capacity" is out of scope of the container (this is something that the user knows about).
> Instead, having the flag in place, we can decide whether allocation should take place or not. When allocation is not obligatory and the capacity reservation flag is set, we do not reallocate but instead do "something else": in case of erase - just remove elements, in case of prepend - move data around (if necessary).
> The flag is a mere part of QCC's state.
The "flag" is basically "a call to reserve was made"? How do I clear the flag?
More information about the Development