CVer wrote
I'm trying to write a function that can create a 2D array,
and my compiler returns no error,
but when I load it in to the VM emulator,
an error : " 'that' segment must be in the heap or screen range site" shows up.
Here's my code and please tell me if you find anything wrong.
I'm appreciated!
class Matrix
{
// the row and column number of the matrix
field int row, col, getValue;
// the matrix
field Array matrix;
/** Construct a row by col empty matrix */
constructor Matrix new (int Arow, int Acol)
{
var int curX, curY;
//var Array xGrid;
let row = Arow;
let col = Acol;
let curX = 0;
let xGrid = Array.new(col);
while(curX < row)
{
let curY = 0;
while (curY < col)
{
let xGrid[curY] = 0;
let curY = curY + 1;
}
let xGrid = matrix[curX];
let curX = curX + 1;
}
return this;
}
...
If you have a X by Y array, don't you need to, at the end of the day, allocate a total of X*Y words of memory? How much total memory are you allocating?
Where are the values in the 'matrix' array getting set?
It looks like you intend for your 'matrix' array to be an array of references to the individual 1D arrays for each row. But you need allocate memory for EACH row of the array and then store the reference to that array in your 'matrix' array.