Dynamic Relocation

C Styled Script
Reference Manual

<< Back  End  Next >>
 
 
INDEX
Introduction
Installation
Using The CSS Executive
Language
   Comments
   Literals
   Var And Const
      Arrays
      Initialization
      Static And Extern
      Dynamic Relocation
   Operators
   Statements And blocks
   Program Flow
   Exception Handling
   Functions
   Predefined Identifiers
Directives
System Library
String Library
Regular Expression Lib.
File Library
Database Library
C API
C++ API
CSS Links
  

One smart feature of CSS is it's ability to dynamicly 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 dynamicly 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.

Globals

Resizing global identifiers is not possible.

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 LandquartLast revised by Peter Koch, 24.02.00<< Back  Top  Next >>