What is the QBytearray, returned by QFile readAll()

5k views Asked by At

I want to ask that if the QFile().readAll () , returns a QByte Array then does it create a byte array on Physical memory or just provides a linked list address containing the positions of Bytes?.

can it create problem in the case of large files which are in GBs.

1

There are 1 answers

2
Boris Dalstein On BEST ANSWER

Yes, it does create a byte array in RAM, copying the whole memory that is in your hard drive. So you will run into issues running QFile::readAll() on huge files.

The documentation for QString QTextStream::readAll() says:

Reads the entire content of the stream, and returns it as a QString. Avoid this function when working on large files, as it will consume a significant amount of memory.

It is not mentioned for QByteArray QIODevice::readAll() (inherited by QFile), but it will be the same, since there is no way the pointers in a QByteArray can point somewhere in your hard disk (must be an address in the virtual memory allocated to the program by the OS, i.e. the stack or the heap).