Results 1 to 6 of 6

Thread: Qt 4.6.3 QByteArray reserve does't influence resize behavior

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Location
    Saint-Peterburg
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt 4.6.3 QByteArray reserve does't influence resize behavior

    Hi!
    According to this part of documentation:
    void QByteArray::reserve ( int size )
    Attempts to allocate memory for at least size bytes. If you know in advance how large the byte array will be, you can call this function, and if you call resize() often you are likely to get better performance. If size is an underestimate, the worst that will happen is that the QByteArray will be a bit slower.

    The sole purpose of this function is to provide a means of fine tuning QByteArray's memory usage. In general, you will rarely ever need to call this function. If you want to change the size of the byte array, call resize().
    the following code mustn't reallocate memory:

    Qt Code:
    1. QByteArray array;
    2. array.reserve(1024);
    3. array.resize(1024);
    4. assert(array.capacity() == 1024); // ok
    5. array.resize(120);
    6. assert(array.capacity() == 1024); // fail
    To copy to clipboard, switch view to plain text mode 
    What is wrong?

    Thank you.
    Last edited by AnatolyS; 21st August 2010 at 11:09. Reason: fixed code decoration

Similar Threads

  1. QVector::reserve() bug?
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2019, 11:34
  2. reserve a space of a list
    By maider in forum Qt Programming
    Replies: 6
    Last Post: 27th November 2009, 10:25
  3. Replies: 9
    Last Post: 25th July 2009, 13:27
  4. Replies: 5
    Last Post: 12th September 2008, 23:13
  5. Strange resize behavior
    By Lykurg in forum Newbie
    Replies: 3
    Last Post: 9th January 2007, 13:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.