I've got a QByteArray
of a given size. Accessing the raw data of the array returns char*
, basically a character array.
I want to fill the QByteArray
's whole size with a uint32_t
value.
What is the safest and most efficient way to do this? I know I could use the Qt functions for appending data into an empty QByteArray, but then it would reallocate memory a lot of time.
I've got the following implementation in my mind, but I'm not sure if it is the best solution:
auto data = QByteArray(fillSize, '0');
auto dataPtr = data.data();
auto fillValue = _byteswap_ulong(getFillValue());
for (char* it = dataPtr; it != dataPtr + fillSize; it += 4)
{
auto help = reinterpret_cast<uint32_t*>(it);
*help = fillValue;
}