Question

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.

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top