Comment #0 by bearophile_hugs — 2014-08-31T09:42:54Z
This program:
enum N = 9;
long[1 << N][1 << N][N][N] a;
void main() {}
With dmd 2.067alpha gives the error messages:
test.d(2,28): Error: index 9 overflow for static array
test.d(2,28): Error: index 9 overflow for static array
This means that the array is too much large for a statically allocated array, but I think the meaning error message is not clear enough. So I suggest something more similar to (a single error message):
test.d(2,28): Error: array 'a' is too much large (512 * 512 * 9 * 9 of 'long') to be allocated statically.
In such cases you usually replace the static array with a heap-allocated array, like:
enum N = 9;
long[][][][] a;
void main() {
a = new typeof(a)(1 << N, 1 << N, N, N);
}
But this generates a very large number of dynamic arrays that waste time and efficiency and stress the garbage collector.
So often a better data structure is an array that has dynamic only one or more of the last coordinates:
enum N = 9;
long[1 << N][1 << N][][] a;
void main() {
a = new typeof(a)(N, N);
}
Unfortunately I think the error message can't explain this idiom to the user.
Comment #1 by bearophile_hugs — 2014-08-31T09:56:33Z
(In reply to bearophile_hugs from comment #0)
> test.d(2,28): Error: array 'a' is too much large (512 * 512 * 9 * 9 of
> 'long') to be allocated statically.
Or even:
test.d(2,28): Error: array 'a' is too much large (512 * 512 * 9 * 9 = 21_233_664 of 'long') to be allocated statically.
Comment #2 by dkorpel — 2023-12-23T11:04:26Z
The error message is now a lot better:
```
`long[32768][32768]` size 262144 * 32768 exceeds 0x7fffffff size limit for static array
```