Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 28, 2011 range violation | ||||
---|---|---|---|---|
| ||||
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? |
February 28, 2011 Re: range violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dr.Smith | 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]);
|
February 28, 2011 Re: range violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | 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; } } |
February 28, 2011 Re: range violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dr.Smith | 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
|
February 28, 2011 Re: range violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dr.Smith | 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; } } } |
Copyright © 1999-2021 by the D Language Foundation