That's interesting. So the container remembers what sort of a reserve
request I made on it, and uses
that as the preferred size whenever the element count of the container changes?

Yes. Calling reserve typically means that you do not want to have extra 
reallocations while updating the container's content (instead you allocate 
sufficient space upfront). In case of QList, we make sure there are no 
reallocations happening unless absolutely necessary, e.g. appending 1 element 
when size == capacity would allocate bigger memory chunk - reservation is a 
hint, but not an obligation. Consequently, QList's shrinking erase also does 
not shrink when capacity is reserved.

--
Best Regards,
Andrei

________________________________
From: Ville Voutilainen <[email protected]>
Sent: Thursday, September 10, 2020 10:39 AM
To: Andrei Golubev <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [Development] Important recent changes in QList/QString/QByteArray

On Wed, 9 Sep 2020 at 16:38, Andrei Golubev <[email protected]> wrote:
>
> I don't understand what this means. Am I supposed to reserve a
> container to its current size before erasing elements
> from it, if I don't want the erase to shrink it?
>
> Yes.

That's interesting. So the container remembers what sort of a reserve
request I made on it, and uses
that as the preferred size whenever the element count of the container changes?
_______________________________________________
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development

Reply via email to