QFile writing more than 32mb at once crashes under windows 32bit
-
Hello everyone!
I have updated my appqt from 5.6 to 5.12.Before the migration this method works fine
bool writeFile(QFile& file, QByteArray data) { int bufferSize = 30 * 1024 * 1024; auto bufferSegment = data.left(bufferSize); while (!bufferSegment.isEmpty()) { qApp->processEvents(); file.write(bufferSegment); data.remove(0, bufferSegment.size()); bufferSegment = data.left(bufferSize); } return true; } const QString absPath = baseDir.absoluteFilePath(fi.filePath); QFileInfo temp_fi(absPath); QDir().mkpath(temp_fi.dir().absolutePath()); writeFile(absPath, fileData(fi.filePath)); QByteArray fileData(const &QString fileName)const { // other code here }After the update, my application are crashing again.
Any ideas?
Thanks in advanced and sorry for my bad english
GG. -
HI
What lines does it crash in ?
Code looks ok. -
@GGAllin said in QFile writing more than 32mb at once crashes under windows 32bit:
bool writeFile(QFile& file, QByteArray data)
Are you sure that you want to pass that by value?
-
@GGAllin said in QFile writing more than 32mb at once crashes under windows 32bit:
bool writeFile(QFile& file, QByteArray data)
Are you sure that you want to pass that by value?
@Kent-Dorfman
Its implicitly shared so not that expensive but good eye :)
https://doc.qt.io/qt-5/implicit-sharing.html -
@Kent-Dorfman
Its implicitly shared so not that expensive but good eye :)
https://doc.qt.io/qt-5/implicit-sharing.htmlbut what might data.remove() do to it then? Also, what about the size of the object if it is passed on the stack? I envision bad thing happening when you pass huge arrays on the window stack.
-
but what might data.remove() do to it then? Also, what about the size of the object if it is passed on the stack? I envision bad thing happening when you pass huge arrays on the window stack.
@Kent-Dorfman
You are right, it should produce a copy since its modified. -
but what might data.remove() do to it then? Also, what about the size of the object if it is passed on the stack? I envision bad thing happening when you pass huge arrays on the window stack.
but what might data.remove() do to it then?
Correct. But then passing the
QByteArrayin by reference, the usual thing to do, is going to alter it in the caller, which we can't have. So really the approach taken for buffering needs to be rethought.QIODevice::write(const char *data, qint64 maxSize)looks like the better overload to utilize.None of which addresses @GGAllin's issue. AS @mrjj asked, where exactly does it crash? If you reduce the buffer size does it make any difference?
-
Hello everyone!
I have updated my appqt from 5.6 to 5.12.Before the migration this method works fine
bool writeFile(QFile& file, QByteArray data) { int bufferSize = 30 * 1024 * 1024; auto bufferSegment = data.left(bufferSize); while (!bufferSegment.isEmpty()) { qApp->processEvents(); file.write(bufferSegment); data.remove(0, bufferSegment.size()); bufferSegment = data.left(bufferSize); } return true; } const QString absPath = baseDir.absoluteFilePath(fi.filePath); QFileInfo temp_fi(absPath); QDir().mkpath(temp_fi.dir().absolutePath()); writeFile(absPath, fileData(fi.filePath)); QByteArray fileData(const &QString fileName)const { // other code here }After the update, my application are crashing again.
Any ideas?
Thanks in advanced and sorry for my bad english
GG.@GGAllin said in QFile writing more than 32mb at once crashes under windows 32bit:
After the update, my application are crashing again.
Please provide a stack trace.