GLBasic User Manual

Main sections

REDIM

REDIM array#$[a1] | [a2][a3]...



Assigns a new size to an array (either bigger or smaller) and keeps the array data that lies within both the old and the new ranges.

You can also use REDIM array#$[0] - this provides a faster way to clear the data in the array without having to deallocate then allocate memory creating an empty array.

If you REDIM a[0], the memory is not freed. Thus, you can re-use a previously dimensioned array much quicker. The REDIM command internally calls a DIM. DIM tries to use the already allocated memory and most times will allocate a bit more memory in advance to have some free space when the array grows. The size depends on the memory useage of the array elements and the current platform. To really free the memory use DIM array[0].

// --------------------------------- //
// Project: REDIM
DIM a[5][4]
Fill(a[])
view(a[], 0)

REDIM a[6][3]
view(a[], 256)

SHOWSCREEN
MOUSEWAIT


// ------------------------------------------------------------- //
// -=# FILL #=-
// ------------------------------------------------------------- //
FUNCTION Fill: f[]
FOR x=0 TO BOUNDS(f[],0)-1
FOR y = 0 TO BOUNDS(f[],1)-1
f[x][y] = x+10*(y+1)
NEXT
NEXT
ENDFUNCTION // FILL

// ------------------------------------------------------------- //
// -=# VIEW #=-
// ------------------------------------------------------------- //
FUNCTION view: f[], dy
FOR x=0 TO BOUNDS(f[],0)-1
FOR y = 0 TO BOUNDS(f[],1)-1
PRINT f[x][y], x*80, y*20 + dy
NEXT
NEXT
ENDFUNCTION // VIEW

See also...