Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading from a file not line-by-line

Assigning a QTextStream to a QFile and reading it line-by-line is easy and works fine, but I wonder if the performance can be inreased by first storing the file in memory and then processing it line-by-line.

Using FileMon from sysinternals, I've encountered that the file is read in chunks of 16KB and since the files I've to process are not that big (~2MB, but many!), loading them into memory would be a nice thing to try.

Any ideas how can I do so? QFile is inhereted from QIODevice, which allows me to ReadAll() it into QByteArray, but how to proceed then and divide it into lines?

like image 294
MadH Avatar asked Nov 18 '25 00:11

MadH


1 Answers

QTextStream has a ReadAll function:

http://doc.qt.io/qt-4.8/qtextstream.html#readAll

Surely that's all you need?

Or you could read all into the QByteArray and QTextStream can take that as an input instead of a QFile.

like image 55
Phil Hannent Avatar answered Nov 19 '25 12:11

Phil Hannent