|
Dynamic relocation |
|
|
One smart feature of CSL is it's ability to dynamically reallocate variables by the resize statement:
var adr = {
{ 1, 'john' },
{ 2, 'fred' }
};
...
// now we need some more adr rows:
resize adr[10][2];
...
The array is reallocated dynamically so you can insert another 8 addresses. There are some things you must be aware of when resizing arrays: Alignment If you change another index than the highest your data will no longer be aligned in columns and rows as before: resize adr[2][3]; Will change the table to: 1 'john' 2 'fred' '' '' Dimensions The number of dimensions cannot be changed. All the following resizes are invalid: resize adr[2][3][4]; resize adr[7]; resize adr; Performance Resizing is no cheap operation. When the total size of the array grows, a new array is allocated internally and the values have to be copied. Avoid tons of small resize's and do the job in bigger chunks to avoid performance problems. Arguments Resizing references is possible when the referenced variable is unindexed:
foo(var &x[])
{
sysLog('resizing from '+sizeof(x)+' to 7');
resize x[7];
}
main()
{
var a[3], b[5][4];
foo(a); // ok, because unindexed.
foo(b[2]); // runtime error thrown in foo!
}
|
||||||||
| Copyright © IBK Landquart | Last revision: 27.05.2002 | << Back Top Next >> |