contents   index   previous   next



Array representation

 

This section on the representation of arrays in memory only deals with automatic arrays which are part of the C portion of ScriptEase. JavaScript uses constructor functions that create instances of JavaScript arrays which are actually objects more than arrays. Everything said in this section is about automatic arrays compared to C arrays. The methods and functions used to work with JavaScript constructed arrays and ScriptEase automatic arrays are different. The following fragment creates a JavaScript array.

 

var aj = new Array();

 

The following line creates an automatic array in ScriptEase.

 

var ac[3][3];

 

The two arrays are different entities that require different methods and functions. For example, the property aj.length provides the length of the aj array, but the function getArrayLength(ac)provides the length of the ac automatic array. When the term array is used in the rest of this section, the reference is to an automatic array. JavaScript arrays are covered in the section on ScriptEase JavaScript.

 

Arrays are used in ScriptEase much like they are in C, except that they are stored differently. A single dimension array, for example, an array of numbers, is stored in consecutive bytes in memory, just as in C, but arrays of arrays are not in consecutive memory locations. The following C declaration:

 

char c[3][3];  // this is the C version

 

indicates that there are nine consecutive bytes in memory. In ScriptEase a similar statement such as the following:

 

var c[2][2] = 'a';  // this is the ScriptEase version

 

indicates that there are at least three arrays of characters, and the third array of arrays has at least three characters in it. Though the characters in c[0] and the characters in c[1] are in consecutive bytes, the two arrays c[0] and c[1] are not necessarily adjacent in memory.

 


Automatic array allocation