[Development] Important recent changes in QList/QString/QByteArray

Andrei Golubev andrei.golubev at qt.io
Thu Sep 10 10:46:53 CEST 2020


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 <ville.voutilainen at gmail.com>
Sent: Thursday, September 10, 2020 10:39 AM
To: Andrei Golubev <andrei.golubev at qt.io>
Cc: development at qt-project.org <development at qt-project.org>
Subject: Re: [Development] Important recent changes in QList/QString/QByteArray

On Wed, 9 Sep 2020 at 16:38, Andrei Golubev <andrei.golubev at qt.io> 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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200910/d753c11c/attachment.html>


More information about the Development mailing list