Dynamic relocation

C Scripting Language
Reference Manual
Version 4.4.0

<< Back  End  Next >>
 
 
INDEX
Introduction
Installation
Using the CSL executive
Language
   Comments
   Numbers
   Literals
   Var and const
      Arrays
      Initialization
      Static and extern
      Dynamic relocation
   Operators
   Statements and blocks
   Program flow
   Trace facility
   Exception handling
   Functions
   Predefined identifiers
Directives
System library
String library
Math library
Regular expression lib.
File library
Database library
Async Communication
Registry/Profile handling
Windows control
C API
C++ Class Interface
CSL links
  

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 >>