Solved Did QByteArray have memory limit?
-
@Mozzie said in Did QByteArray have memory limit?:
QbyteArry is greater than (2 * 1024 * 1024 - 26), it crashed.
@Mozzie said in Did QByteArray have memory limit?:
data.reserve(1024 * 1024 * 1024 * 2 - 25); // crash
data.reserve(1024 * 1024 * 1024 * 2 - 26); // not crashThere is a
' * 1024'
missing or too much.Just by doing
QByteArray data; data.reserve(1024 * 1024 * 1024 * 2 - 25)
I get an overflow compiler warning. because I'm trying to pass more than
sizeof(int)
as parameter
warning: overflow in expression; result is -2147483622 with type 'int'
(64bit GCC @ Ubuntu18.04, btw)Is it possible for you to split the ByteArray?
-
@Pl45m4
Thanks
It is just a warning, and if you useqDebug() << 1024 * 1024 * 1024 * 2 - 25;
it is less than 2 ^ 32 / 2.
I am thinking about how to split the QbyteArray and not write disk frequently
-
Hi,
As @JonB already suggested, mapping the file might be a better solution.
-
@SGaist said in Did QByteArray have memory limit?:
As @JonB already suggested, mapping the file might be a better solution.
Afaiu the OP is downloading a file from the net - so mmap is not really possible. Simply writing it in chunks should work. QByteArray will not handle more than 2GB in Qt5.
-
@SGaist
Thanks,
If use mmap, It seems I need to create a file with the same size of download file, this is pretty slow and waste. -
@Christian-Ehrlicher
Thanks .Iis there any difference between write data in one time and write data in chunks on disk operation?
I mean which way have small impact on disk.And it seems hard to make sure download is complete so that the file will be complete after write into disk .
-
@Mozzie said in Did QByteArray have memory limit?:
I mean which way have small impact on disk.
If you've a good OS both is equal.
-
@Christian-Ehrlicher said in Did QByteArray have memory limit?:
QByteArray will not handle more than 2GB in Qt5.
Is there any document about "QByteArray will not handle more than 2GB in Qt5"?
-
-
@J-Hilk
Thank you. That's what I'm looking for.
But, I did not see this in my qt-creator document, I'm using qt5.12.6 -
@Mozzie said in Did QByteArray have memory limit?:
Is there any document about "QByteArray will not handle more than 2GB in Qt5"?
Just take a look at the ctors, the access functions and the resize/size ones and it's clear that it can't contain more than 2GB ...