From what I understands, when I create a static array, say, int[] array = new int[N];, the run time actually looks for N*4 bytes of memory whose addresses are also continuous. right?
So what if the run time can’t find continuous memory addresses?
for example, if my memory is 128MB, and in my application N = 25M, which means I need 100MB memory for my array. Is it possible for this creation of array to fail? Is it possible, the 100MB of memory in need can’t be located because there are too many memory fragments?
thanks
Yes it can fail. In that case an
OutOfMemoryExceptionwill be thrown. An easy way to test this is the following:(This assumes C#, behavior in Java will be similar)