[Qt-interest] How to clear QVector without releasing memory?

Nikos Chantziaras realnc at arcor.de
Tue Jun 21 03:44:46 CEST 2011


On 06/20/2011 06:16 PM, Atlant Schmidt wrote:
> Nikos:
>
>    (You switched from talking about resize() to reserve();
>    I'll assume that's a typo.)

No, I did mean reserve().  Because that's what you're using to guarantee 
a certain vector capacity and thus memory allocation.


>
>    Here's the description for resize() (from the Qt 4.7.1 docs):
>
>      void QVector::resize ( int size )
>
>      Sets the size of the vector to size. If size is
>      greater than the current size, elements are added
>      to the end; the new elements are initialized with
>      a default-constructed value. If size is less than
>      the current size, elements are removed from the end.
>
>      See also size().
>
>
>    It seems to me that there's no promise that this clears
>    existing elements in the vector (except that elements
>    at the end will be destroyed if you're shortening the
>    vector). In fact, the behaviour when the new size ==
>    the existing size is completely unspecified!

What do you mean with "clears existing elements".  How can you "clear" 
an element?  This is not an operation I'm familiar with.



More information about the Qt-interest-old mailing list