AnatolyS
21st August 2010, 10:32
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:
QByteArray array;
array.reserve(1024);
array.resize(1024);
assert(array.capacity() == 1024); // ok
array.resize(120);
assert(array.capacity() == 1024); // fail
What is wrong?
Thank you.
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:
QByteArray array;
array.reserve(1024);
array.resize(1024);
assert(array.capacity() == 1024); // ok
array.resize(120);
assert(array.capacity() == 1024); // fail
What is wrong?
Thank you.