Let’s say we have a string which its length is very big, let’s say even bigger than max_int.
string str="this should contain a long string";
if I want to reach to the str[100000000000].
How should I do it?
When I try to put an index which its type isn’t int I get the following error:
The best overloaded method match for ‘string.this[int]’ has some invalid arguments
The maximal size of a single object was 2GB prior .NET 4.5, so you could never have a string that big, so there was no purpose in trying to use an index this large.
In .NET 4.5, you can increase that limit. Quote from MSDN:
“By default, when you run a 64-bit managed application on a 64-bit Windows operating system, you can create an object of no more than 2 gigabytes (GB). However, in the .NET Framework 4.5, you can increase this limit. For more information, see the gcAllowVeryLargeObjects element.”
However, most containers still have interfaces based on
intand even for arrays this won’t help…“The maximum number of elements in an array is UInt32MaxValue.”
…which is 4,294,967,295 which is still smaller than 100,000,000,000 you proposed.
Do you really need to have that much continuous memory? Why not split your data to smaller chunks?