'that' segment must be in the heap or screen range site

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

'that' segment must be in the heap or screen range site

CVer
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;
        }
...
Reply | Threaded
Open this post in threaded view
|

Re: 'that' segment must be in the heap or screen range site

ivant
The declaration of xGrid is commented, but xGrid is still used.

You only seem to allocate space for a single column of the matrix. And I'm not sure what you're trying to do with the two nested loops.
Reply | Threaded
Open this post in threaded view
|

Re: 'that' segment must be in the heap or screen range site

WBahn
Administrator
In reply to this post by CVer
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.
Reply | Threaded
Open this post in threaded view
|

Re: 'that' segment must be in the heap or screen range site

CVer
In reply to this post by ivant
@ivant

Thanks for replying!

Should I put "let xGrid = Array.new(col);" in the first loop?
I've done this but the error still remain.

In my matrix class, I construct a empty matrix with given row and column in my constructor,
and I build one method to set the matrix element and one to get the element.
Reply | Threaded
Open this post in threaded view
|

Re: 'that' segment must be in the heap or screen range site

WBahn
Administrator
You are not storing ANYTHING in your matrix array. You are not even allocating any memory to it. Yet you are using whatever is stored there as an array reference. If the value that happens to be there is not in the heap or memory segments, the VM emulator will throw an error.

You need to clearly define what your matrix array is and what information it is supposed to contain. Then you need to make sure that you store that information in it before you use that information from it.