[Qt-interest] How to clear QVector without releasing memory?
Nikos Chantziaras
realnc at arcor.de
Mon Jun 20 15:53:43 CEST 2011
I think even though it's not explicitly spelled out in the docs, it's
implied. reserve() would have no meaning otherwise. What's the point
of offering this function if Qt would then go ahead and lower the
capacity again?
On 06/20/2011 04:49 PM, Schimkowitsch Robert wrote:
> resize(0) does really seem to be an option here. The way I understood
> the source code, it really will not free up memory when I resize the
> vector. What bothers me a little is that I would rely on undocumented
> behaviour here, i.e. it might change without notice.
>
> But the way I see it, there IS no documented way to remove items without
> deallocating memory.
>
> Robert Schimkowitsch
>
>
> -----Original Message-----
> From: qt-interest-bounces+robert.schimkowitsch=andritz.com at qt.nokia.com
> [mailto:qt-interest-bounces+robert.schimkowitsch=andritz.com at qt.nokia.co
> m] On Behalf Of Nikos Chantziaras
> Sent: Friday, June 17, 2011 6:39 PM
> To: qt-interest at qt.nokia.com
> Subject: Re: [Qt-interest] How to clear QVector without releasing
> memory?
>
> On 06/17/2011 05:19 PM, Schimkowitsch Robert wrote:
>> Hi,
>>
>> I have a QVector that I want to re-use many times as a buffer. As the
>> application is long-running on a low memory device, memory
> fragmentation
>> might be an issue.
>>
>> To keep this in check, I would like to reserve() the QVector once,
> with
>> the maximum size I am going to need, and then re-use it without ever
>> freeing up memory.
>>
>> The only ways to clear all items from the vector I found will also
>> deallocate memory.
>>
>> What is the performace-optimal way to clear a QVector without
>> deallocating memory?
>
> QVector::resize(0). It doesn't clear anything, which means it's as fast
>
> as it can possibly get. The docs are hinting that this does not
> deallocate memory:
>
> "If you know in advance how large the vector will be, you can call this
> function, and if you call resize() often you are likely to get better
> performance."
>
> Dot not use QVector::clear(). This one will deallocate memory,
> according the docs.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
> #####################################################################################
>
> This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
>
> Thank You.
>
> #####################################################################################
More information about the Qt-interest-old
mailing list