I have noticed that in some cases after executing the following code
void appendToArray(QByteArray &array, const char *source, int size) {
void *p1 = array.data();
array.append(dest, size);
void *p2 = array.data();
}
p1 and p2 become different. But I always thought that append() method doesn't affect inner QByteArray memory "at the beginning" - it just appends some bytes to the end of object; Am I wrong?
From the QByteArray doc page (http://doc.qt.io/qt-4.8/qbytearray.html)
When you append() data to a non-empty array, the array will be reallocated and the new data copied to it.
This may not happen all of the time, as the array may have enough memory allocated to store the new item. However, when it needs to get more space to store more data, it reallocates memory for the entire array and copies the existing data across. This is so that it can maintain a single contiguous data array.