In the awful world of the standard library we call vector.shrink_to_fit() to ensure that. Note that while you have your «please free the memory» use-case someone might have the «please do not free memory, I still need it» use-case.
Ivan > 3 сент. 2020 г., в 09:40, Jaroslaw Kobus <[email protected]> написал(а): > >> ________________________________________ >> From: Development <[email protected]> on behalf of Giuseppe >> D'Angelo via Development <[email protected]> >> Sent: Wednesday, September 2, 2020 9:37 PM >> To: Andrei Golubev; [email protected]; Ville Voutilainen >> Subject: Re: [Development] Important recent changes in >> QList/QString/QByteArray >> >> On 02/09/2020 21:18, Andrei Golubev wrote: >>> Also not sure whether it is an implementation detail or the behavior >>> that should always be anticipated. >> >> People build performance sensitive code assuming the cost of certain >> operations -- like, assuming that erasing elements from a vector never >> reallocates it; and that the only operation that sheds capacity is >> squeeze(), everything else (incl. clear(), incl. resize(0)) keeps the >> capacity (*). We should stop backstabbing them... > > People sometimes care about memory consumption, too. If user's object > contains a vector consisting of exactly one element, he may be surprised > that it still consumes a place for one million elements, just because one > minute ago he removed 999.999 items. If he is creating hundreds > of such objects sequentially, his app may not run at all (however, will > perform very well). > > Jarek > _______________________________________________ > Development mailing list > [email protected] <mailto:[email protected]> > https://lists.qt-project.org/listinfo/development > <https://lists.qt-project.org/listinfo/development>
_______________________________________________ Development mailing list [email protected] https://lists.qt-project.org/listinfo/development
