Dynamic Relocation |
|
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: AlignmentIf 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' '' '' DimensionsThe number of dimensions cannot be changed. All the following resizes are invalid: resize adr[2][3][4]; resize adr[7]; resize adr; PerformanceResizing 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. GlobalsResizing global identifiers is not possible. ArgumentsResizing 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 revised by Peter Koch, 24.02.00 | << Back Top Next >> |