问题
I am using Qt 5.9 on Ubuntu 16.04 64-bit architecture. I had a requirement in which I need to take input from a file which can have characters in the range of 10^8. Unfortunately breaking down the file in parts and working on that is not an option as I need the entire data in the file for the operation of my code.
From what I have thought out so far I plan to store the file data in a QString(any other suggestions are welcome). What is the maximum size that QString can store in this regard? I have seen the following links but none of them provide a concrete answer:
- Link 1
- Link 2
Since my data falls very close to the limits defined in Link 1 of 2^30, is QString a suitable choice for this?
Note: All the data will be hexadecimal and I will need to convert the QString to a QByteArray down the line.
My other concern is if it will be able to handle that many number of characters efficiently. From what I have read Qt optimizes the string length as a means of fine tuning QString's memory usage. Will this impact the file read operation considering the huge amount of characters(in terms of time taken).
Adding a sample code for read operation:
void readData (QString file) {
QFile f(file);
if (!f.open(QFile::ReadOnly | QFile::Text)) break;
QTextStream in(&f);
QString data=in.readAll(); // alternately, this can be read line by line along with QStringBuilder
}
来源:https://stackoverflow.com/questions/46237476/maximum-size-of-qstring