I got to know the maximum object size in C# is 2GB. Also there is a memory limit for each particular PC and either it is 32 or 64 bit.
In my application I need an array of integers as big as possible. So what I need is to take care of OutOFMemoryException until the biggest possible array can be made!
I end up with the code below:
private int[] AllIntegers()
{
int[] all;
int divider = 2;
try
{
all = new int[int.MaxValue];
}
catch (OutOfMemoryException)
{
all = new int[int.MaxValue / divider];
}
//Probably will fail again. how to efficently loop the catch again
for (int i = 0; i < all.Length; i++)
{
all[i] = i;
}
return all;
}
the code will also fail, what I am looking for is a proper way of looping untill the array can be made!
EDIT: I do not like the idea of this, since I think it’s wrong to hold such a large amount of data
(and an array of all integers?)
But, here’s what you’re looking for:
EDIT2:
Maybe elaborate us with what you are trying to achieve?