Sundaze123
Sundaze123

Reputation: 23

Memory limit exceeded with the use of a 2D array

This line of code creates an error message "Memory limit exceeded" when length is 100,000 and I don't quite understand why.

int[][] multiply = new int[length][length];

Upvotes: 1

Views: 413

Answers (1)

Yunnosch
Yunnosch

Reputation: 26703

You try to make an array of 100,000 * 100,000 entries of probably 4 bytes each.
That is 40,000,000,000 bytes, around 40GB. Even if you have that kind of memory installed, the system will probably enforce some limits long before that.

Upvotes: 10

Related Questions