digitalmars.D.learn - range violation
- Dr.Smith (3/3) Feb 28 2011 With multidimensional arrays greater than 150x150, I get a range violati...
- Nick Treleaven (8/11) Feb 28 2011 Can you show some code or a test case?
- Dr.Smith (12/12) Feb 28 2011 For example:
- bearophile (10/26) Feb 28 2011 You receive the same stack overflow error with this simpler code:
- Andrej Mitrovic (11/11) Feb 28 2011 That's because data2 has length 1000, each of which has an array of
With multidimensional arrays greater than 150x150, I get a range violation at run time: "core.exception.RangeError pweight(54): Range violation" Is this a bug? Is there a work-around?
Feb 28 2011
On Mon, 28 Feb 2011 16:07:41 +0000, Dr.Smith wrote:With multidimensional arrays greater than 150x150, I get a range violation at run time: "core.exception.RangeError pweight(54): Range violation" Is this a bug? Is there a work-around?Can you show some code or a test case? My sample below seems to work fine (but I'm still using an older dmd - v2.049): int[151][151] x; x[150][150] = 7; writeln(x[150][150]);
Feb 28 2011
For example:
double [string] data;
double [200][1000] data2;
for(int i = 0; i < 200; i++) {
for(int j = 0; j < 1000; j++) {
// fake multi-dim works
string str = to!string(i) ~ "," ~ to!string(j);
data[str] = someNumber;
// real multi-dim does not work
data2[i][j] = someNumber;
}
}
Feb 28 2011
Dr.Smith:
For example:
double [string] data;
double [200][1000] data2;
for(int i = 0; i < 200; i++) {
for(int j = 0; j < 1000; j++) {
// fake multi-dim works
string str = to!string(i) ~ "," ~ to!string(j);
data[str] = someNumber;
// real multi-dim does not work
data2[i][j] = someNumber;
}
}
You receive the same stack overflow error with this simpler code:
void main() {
double[200][1000] a;
}
Keep in mind this is a fixed-sized array, so it's allocated on the stack.
On Windows with DMD if you add a switch like this, to increase max stack size,
that code works:
-L/STACK:10000000
Bye,
bearophile
Feb 28 2011
That's because data2 has length 1000, each of which has an array of
length 200. Not the other way around. This works:
double[200][1000] data2;
void main()
{
for(int i = 0; i < 1000; i++) {
for(int j = 0; j < 200; j++) {
data2[i][j] = 4.0;
}
}
}
Feb 28 2011









bearophile <bearophileHUGS lycos.com> 