What is the maximum length of string that QString object can hold?
-
wrote on 11 Oct 2011, 10:54 last edited by
I mean how many characters we can assign at once to Qstring object?
-
wrote on 11 Oct 2011, 11:04 last edited by
As far as I remember it is 2^30.
-
wrote on 11 Oct 2011, 11:05 last edited by
Ya I was also thinking like that. Thank's ...........
-
wrote on 11 Oct 2011, 11:28 last edited by
I have to admit that this piece of information dates back where 64 bit didn't really matter. However, you shouldn't rely on that you can store more than 2^30 in a QString, because usually you can't - even on 64 bit architectures.
-
wrote on 11 Oct 2011, 13:04 last edited by
2^30 is 1073741824 characters, but QString being UTF16, that means a memory usage of 2.147.483.648 bytes, plus some additional bytes around that. For a single piece of data in your application. That's 2 GB worth of data, if I'm not mistaken. Not the best idea to keep that in a single block of memory, and then I am not even talking yet of temporaries that might also be in memory at the same time (like a byte array of the same size from a file you just read, for instance).
To summarize: if you find yourself wondering about reaching this limit, you had better start wondering about your design at a more fundamental level.
1/7