What's the optimal way to read QFile into a `vector<char> buffer`?
Unsolved
General and Desktop
-
We have an app that read a large chunk of data frequently from various files via
QFile::readAll
. The file's size is not fixed. We have to copy the returnedQByteArray
to thevector<char>
buffer.What if I don't want this little overhead and want extreme fast file reading?
Would
QFileDevice::map
thenmemcpy
be faster?Should I use
DataStream
?Or just plain
read
?If plain
read
is preferred, then please criticize and tell me why the piece of code that i came up with maybe stupid :)Why should the chunk_size be 1024? I saw many different values based on public codes.
Also Can I read the file's content directly into the
vector<char>
?QFile f("what.txt"); std::vector<char> target; int chunk_size = 1024; QByteArray buffer; f.open(QIODevice::ReadOnly); while (!f.atEnd()) { buffer = f.read(chunk_size); target.insert(target.end(), buffer.cbegin(), buffer.cend()); } f.close();
Thanks for your help!
-