Revision history for KeyPgRedim


Revision [22641]

Last edited on 2019-03-28 03:22:54 by fxm [Suppressed the type declaration that is redundant when resizing a dynamic array (in examples)]
Additions:
ReDim Preserve array(0 to 9)
ReDim Preserve array(1 To 4, 1 To 4)
ReDim Preserve array(1 To 2, 1 To 4)
Deletions:
ReDim Preserve array(0 to 9) As Integer
ReDim Preserve array(1 To 4, 1 To 4) As Integer
ReDim Preserve array(1 To 2, 1 To 4) As Integer


Revision [22557]

Edited on 2019-01-31 08:45:44 by fxm [Added sentence when used with in a UDT]
Additions:
When used with in a user-defined type, ##**Redim**## creates variable-length arrays while being able to pre-size them with constant subscripts.


Revision [22258]

Edited on 2018-04-02 04:14:47 by fxm [Added example with complex array expression requiring enclosing parentheses]
Additions:
- For use of ##**Redim**## with a complex array expression (especially if the array expression itself contains parentheses), the array expression must be enclosed in parentheses in order to solve the parsing ambiguity.
{{fbdoc item="filename" value="examples/manual/array/redim3.bas"}}%%(freebasic)
'' Define a variable-length array as UDT field
Type UDT
Dim As Integer array(Any)
End Type
Dim As UDT u(0 To 3)
'' For use of Redim with a complex array expression
'' (especially if the array expression itself contains parentheses),
'' the array expression must be enclosed in parentheses
'' in order to solve the parsing ambiguity:
'' Redim u(0).array(0 To 9)
'' induces error 4: Duplicated definition, u in 'Redim u(0).array(0 To 9)'
Redim (u(0).array)(0 To 9)
Deletions:
- For use of ##**Redim**## (resizing) with a complex expression, (especially if the array expression itself contains parentheses), the array expression must be enclosed in parentheses in order to solve the parsing ambiguity.
''


Revision [22173]

Edited on 2018-02-04 23:52:53 by fxm [Formatting 'NOTES' paragraph for the '.chm' file]
Additions:
- ##[[KeyPgPreserve|Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory (if resizing is not possible, the whole original data block is first shifted to another memory location).
- Its behavior (with a single dimension) is well-defined only when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
- With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict (because multidimensional arrays are stored in row-major order : values differing only in the last index are contiguous).
Deletions:
##[[KeyPgPreserve|Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory (if resizing is not possible, the whole original data block is first shifted to another memory location).
Its behavior (with a single dimension) is well-defined only when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict (because multidimensional arrays are stored in row-major order : values differing only in the last index are contiguous).


Revision [22131]

Edited on 2018-02-04 08:09:16 by fxm [Formatting]
Additions:
##[[KeyPgPreserve|Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory (if resizing is not possible, the whole original data block is first shifted to another memory location).
Its behavior (with a single dimension) is well-defined only when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict (because multidimensional arrays are stored in row-major order : values differing only in the last index are contiguous).
Deletions:
##[[KeyPgPreserve|Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory (if resizing is not possible, the whole original data block is first shifted to another memory location).
Its behavior (with a single dimension) is well-defined only when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict (because multidimensional arrays are stored in row-major order : values differing only in the last index are contiguous).


Revision [21811]

Edited on 2017-08-12 02:08:03 by fxm [Added in note#1 that "Redim Preserve" may change the array data location in memory]
Additions:
##[[KeyPgPreserve|Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory (if resizing is not possible, the whole original data block is first shifted to another memory location).
Deletions:
##[[KeyPgPreserve|Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.


Revision [21754]

Edited on 2017-05-11 11:52:06 by fxm [Rewording of note#1]
Additions:
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict (because multidimensional arrays are stored in row-major order : values differing only in the last index are contiguous).
Deletions:
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict (because multidimensional arrays are stored by row-major order : values differing only in the last index are contiguous).


Revision [21753]

Edited on 2017-05-11 09:33:57 by fxm [Rewording of note#1]
Additions:
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict (because multidimensional arrays are stored by row-major order : values differing only in the last index are contiguous).
Deletions:
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict.


Revision [21752]

Edited on 2017-05-08 01:24:19 by fxm [Rewording of note#3]
Additions:
- Using ##**Redim**## within a member procedure with an array that contains the instance of the object class is undefined, and will [hopefully] result in horrible crashes (if array data are shifted in memory, the ##[[KeyPgThis|This]]## reference becomes incoherent, similarly to a dangling pointer).
Deletions:
- Using ##**Redim**## within a member procedure with an array that contains the instance of the object class is undefined, and will [hopefully] result in horrible crashes (when array data are shifted in memory, the ##[[KeyPgThis|This]]## reference may become incoherent, similarly to a dangling pointer).


Revision [21751]

Edited on 2017-05-08 01:19:44 by fxm [Rewording of note#3]
Additions:
- Using ##**Redim**## within a member procedure with an array that contains the instance of the object class is undefined, and will [hopefully] result in horrible crashes (when array data are shifted in memory, the ##[[KeyPgThis|This]]## reference may become incoherent, similarly to a dangling pointer).
Deletions:
- Using ##**Redim**## within a member procedure with an array that contains an instance of the object class is undefined, and will [hopefully] result in horrible crashes.


Revision [21106]

Edited on 2016-03-13 09:45:19 by fxm [Formatting]

No Differences

Revision [20482]

Edited on 2016-02-10 16:07:36 by DkLwikki [Update link format]
Additions:
##**Redim** [ [[KeyPgShared|Shared]] ] //symbolname//([//subscript// [, ...]]) As [[DataType|datatype]] [, ...]##
##**Redim** [ [[KeyPgShared|Shared]] ] As [[DataType|datatype]] //symbolname//([//subscript// [, ...]]) [, ...]##
##**Redim** [ [[KeyPgPreserve|Preserve]] ] //symbolname//([//subscript// [, ...]]) [, ...]##
##[[KeyPgShared|Shared]]##
##[[KeyPgPreserve|Preserve]]##
When used with an existing array, the contents of the array will be preserved during the resize. Note that in some cases ##[[KeyPgPreserve|Preserve]]## will not preserve data at its original index, see below.
The lower and upper bound range for a dimension of the array. Lower bound defaults to zero (##0##), or the default ##[[KeyPgOptionbase|Base]]##, if not specified.
##[[DataType|datatype]]##
##**Redim**## can be used to define new variable-length arrays, or resize existing variable-length arrays while keeping the same number of dimensions. ##**Redim**## always produces variable-length arrays, so, unlike ##[[KeyPgDim|Dim]]##, variable-length arrays can be defined with constant subscripts.
When defining a new variable-length array, its elements are default constructed. For simple data types like ##[[KeyPgInteger|Integer]]## or ##[[KeyPgDouble|Double]]##, the elements are initialized to zero (##0##). For user-defined types with a default constructor, that will be called.
- ##**Redim** [[KeyPgPreserve|Preserve]]## may not work as expected in all cases:
##[[KeyPgPreserve|Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds made with ##[[KeyPgDim|Dim]]##. This includes the fixed-size arrays contained in UDTs (user-defined ##[[KeyPgType|Type]]##s). This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.
array(i, j) = n
Print Using "## "; array(i, j);
n += 1
Print Using "## "; array(i, j);
Print Using "## "; array(i, j);
- ##[[KeyPgPreserve|Preserve]]## was in Visual Basic, but not in QBASIC.
- ##[[KeyPgCommon|Common]]##
- ##[[KeyPgDim|Dim]]##
- ##[[KeyPgErase|Erase]]##
- ##[[KeyPgExtern|Extern]]##
- ##[[KeyPgLbound|Lbound]]##
- ##[[KeyPgPreserve|Preserve]]##
- ##[[KeyPgShared|Shared]]##
- ##[[KeyPgStatic|Static]]##
- ##[[KeyPgUbound|Ubound]]##
- ##[[KeyPgVar|Var]]##
Deletions:
##**Redim** [ [[KeyPgShared Shared]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]##
##**Redim** [ [[KeyPgShared Shared]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]##
##**Redim** [ [[KeyPgPreserve Preserve]] ] //symbolname//([//subscript// [, ...]]) [, ...]##
##[[KeyPgShared Shared]]##
##[[KeyPgPreserve Preserve]]##
When used with an existing array, the contents of the array will be preserved during the resize. Note that in some cases ##[[KeyPgPreserve Preserve]]## will not preserve data at its original index, see below.
The lower and upper bound range for a dimension of the array. Lower bound defaults to zero (##0##), or the default ##[[KeyPgOptionbase Base]]##, if not specified.
##[[DataType datatype]]##
##**Redim**## can be used to define new variable-length arrays, or resize existing variable-length arrays while keeping the same number of dimensions. ##**Redim**## always produces variable-length arrays, so, unlike ##[[KeyPgDim Dim]]##, variable-length arrays can be defined with constant subscripts.
When defining a new variable-length array, its elements are default constructed. For simple data types like ##[[KeyPgInteger Integer]]## or ##[[KeyPgDouble Double]]##, the elements are initialized to zero (##0##). For user-defined types with a default constructor, that will be called.
- ##**Redim** [[KeyPgPreserve Preserve]]## may not work as expected in all cases:
##[[KeyPgPreserve Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds made with ##[[KeyPgDim Dim]]##. This includes the fixed-size arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s). This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.
array(i, j) = n
Print Using "## "; array(i, j);
n += 1
Print Using "## "; array(i, j);
Print Using "## "; array(i, j);
- ##[[KeyPgPreserve Preserve]]## was in Visual Basic, but not in QBASIC.
- ##[[KeyPgCommon Common]]##
- ##[[KeyPgDim Dim]]##
- ##[[KeyPgErase Erase]]##
- ##[[KeyPgExtern Extern]]##
- ##[[KeyPgLbound Lbound]]##
- ##[[KeyPgPreserve Preserve]]##
- ##[[KeyPgShared Shared]]##
- ##[[KeyPgStatic Static]]##
- ##[[KeyPgUbound Ubound]]##
- ##[[KeyPgVar Var]]##


Revision [17230]

Edited on 2014-09-05 09:55:06 by DkLwikki [Formatting]
Additions:


- ##**Redim** [[KeyPgPreserve Preserve]]## may not work as expected in all cases:
##[[KeyPgPreserve Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
Its behavior (with a single dimension) is well-defined only when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict.
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds made with ##[[KeyPgDim Dim]]##. This includes the fixed-size arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s). This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.
- Using ##**Redim**## within a member procedure with an array that contains an instance of the object class is undefined, and will [hopefully] result in horrible crashes.
- For use of ##**Redim**## (resizing) with a complex expression, (especially if the array expression itself contains parentheses), the array expression must be enclosed in parentheses in order to solve the parsing ambiguity.
Deletions:
- ##**Redim** [[KeyPgPreserve Preserve]]## may not work as expected in all cases:
##[[KeyPgPreserve Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
Its behavior (with a single dimension) is well-defined only when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict.
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds made with ##[[KeyPgDim Dim]]##. This includes the fixed-size arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s). This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.
- Using ##**Redim**## within a member procedure with an array that contains an instance of the object class is undefined, and will [hopefully] result in horrible crashes.
- For use of ##**Redim**## (resizing) with a complex expression, (especially if the array expression itself contains parentheses), the array expression must be enclosed in parentheses in order to solve the parsing ambiguity.


Revision [17226]

Edited on 2014-09-03 03:14:57 by FxMwikki [Redim cannot modify the number of dimensions - UDTs support now the var-len arrays]
Additions:
##**Redim**## can be used to define new variable-length arrays, or resize existing variable-length arrays while keeping the same number of dimensions. ##**Redim**## always produces variable-length arrays, so, unlike ##[[KeyPgDim Dim]]##, variable-length arrays can be defined with constant subscripts.
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds made with ##[[KeyPgDim Dim]]##. This includes the fixed-size arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s). This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.
Deletions:
##**Redim**## can be used to define new variable-length arrays, or resize existing variable-length arrays. ##**Redim**## always produces variable-length arrays, so, unlike ##[[KeyPgDim Dim]]##, variable-length arrays can be defined with constant subscripts.
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds made with ##[[KeyPgDim Dim]]##. This includes arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs. This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.


Revision [17092]

Edited on 2014-06-13 14:05:15 by FxMwikki [Added note about need of enclosing in parentheses some complex expressions of array]
Additions:
- For use of ##**Redim**## (resizing) with a complex expression, (especially if the array expression itself contains parentheses), the array expression must be enclosed in parentheses in order to solve the parsing ambiguity.
Deletions:
- For ##**Redim**## some complex array expression, (especially if the array expression itself contains parentheses), the array expression must be enclosed in parentheses in order to solve the parsing ambiguity.


Revision [17091]

Edited on 2014-06-13 13:06:32 by FxMwikki [Added note about need of enclosing in parentheses some complex expressions of array]
Additions:
- For ##**Redim**## some complex array expression, (especially if the array expression itself contains parentheses), the array expression must be enclosed in parentheses in order to solve the parsing ambiguity.


Revision [16370]

Edited on 2012-10-12 15:51:47 by FxMwikki [Correction of first example output + suppression of link "redim" to itself]
Deletions:
- ##[[KeyPgRedim Redim]]##


Revision [16369]

Edited on 2012-10-12 01:50:33 by FxMwikki [Correction of first example output]
Additions:
5 0
Deletions:
5 5


Revision [15456]

Edited on 2011-10-18 16:26:59 by CountingPine [Remove redundant "As ..." syntax for resizing; reorder Shared/Preserve in Params section]
Additions:
{{fbdoc item="syntax"}}
##**Redim** [ [[KeyPgShared Shared]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]##
##**Redim** [ [[KeyPgShared Shared]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]##
##**Redim** [ [[KeyPgPreserve Preserve]] ] //symbolname//([//subscript// [, ...]]) [, ...]##
Deletions:
{{fbdoc item="syntax"}}##
**Redim** [ [[KeyPgShared Shared]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]
**Redim** [ [[KeyPgShared Shared]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]
**Redim** [ [[KeyPgPreserve Preserve]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]
**Redim** [ [[KeyPgPreserve Preserve]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]
##


Revision [15455]

Edited on 2011-10-18 16:22:08 by CountingPine [Separate out declaring/resizing syntax (at the expense of showing which order they may go in), sligh]
Additions:
Declaring a Dynamic Array:
**Redim** [ [[KeyPgShared Shared]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]
**Redim** [ [[KeyPgShared Shared]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]
Resizing a Dynamic Array:
**Redim** [ [[KeyPgPreserve Preserve]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]
**Redim** [ [[KeyPgPreserve Preserve]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]
When used with an existing array, the contents of the array will be preserved during the resize. Note that in some cases ##[[KeyPgPreserve Preserve]]## will not preserve data at its original index, see below.
Deletions:
**Redim** [ [[KeyPgPreserve Preserve]] ] [ [[KeyPgShared Shared]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]
**Redim** [ [[KeyPgPreserve Preserve]] ] [ [[KeyPgShared Shared]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]
When used with an existing array, the contents of the array will be preserved during the resize. Note that ##[[KeyPgPreserve Preserve]]## will not work properly in all cases.


Revision [15454]

Edited on 2011-10-18 15:37:24 by FxMwikki [Swap position between the two parameters Shared and Preserve]
Additions:
Defines or resizes a variable-length array
Deletions:
Defines or resizes a variable-length array


Revision [15453]

Edited on 2011-10-18 15:37:02 by FxMwikki [Swap position between the two parameters Shared and Preserve]
Additions:
Defines or resizes a variable-length array
Deletions:
Defines or resizes a variable-length array


Revision [15452]

Edited on 2011-10-18 15:29:37 by FxMwikki [Swap position between the two prameters Shared and Preserve]
Additions:
**Redim** [ [[KeyPgPreserve Preserve]] ] [ [[KeyPgShared Shared]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]
**Redim** [ [[KeyPgPreserve Preserve]] ] [ [[KeyPgShared Shared]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]
Deletions:
**Redim** [ [[KeyPgShared Shared]] ] [ [[KeyPgPreserve Preserve]] ] //symbolname//([//subscript// [, ...]]) As [[DataType datatype]] [, ...]
**Redim** [ [[KeyPgShared Shared]] ] [ [[KeyPgPreserve Preserve]] ] As [[DataType datatype]] //symbolname//([//subscript// [, ...]]) [, ...]


Revision [14842]

Edited on 2010-09-30 15:22:11 by MjKwikki [Small editing re "ReDim Preserve" on Multi-dim arrays]
Additions:
Its behavior (with a single dimension) is well-defined only when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
With multiple dimensions, only the upper bound of only the first dimension may be safely increased. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensions are resized at all, the effects can be hard to predict.
Deletions:
Its behavior is only well-defined when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
If there are multiple dimensions, only the upper bound of the first dimension may be changed safely. If lower-order dimensions are resized at all, the effects can be hard to predict.


Revision [14135]

Edited on 2009-05-01 21:30:23 by KristopherWindsor [Small editing re "ReDim Preserve" on Multi-dim arrays]
Additions:
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds made with ##[[KeyPgDim Dim]]##. This includes arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs. This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.
Deletions:
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds. This includes arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs. This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.


Revision [14134]

Edited on 2009-05-01 15:57:07 by CountingPine [Additional note about fixed-len array params]
Additions:
- ##**Redim**## cannot be used on fixed-size arrays - i.e. arrays with constant bounds. This includes arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs. This also includes fixed-length arrays passed as parameters in a function. ""FreeBASIC"" cannot prevent you trying this at compile-time, but the results at run-time will be undefined.
Deletions:

- ##**Redim**## cannot be used on fixed-size arrays, i.e. arrays with constant bounds. This includes arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs.


Revision [13721]

Edited on 2008-09-11 13:05:18 by CountingPine [Additional note about fixed-len array params]
Additions:
##[[KeyPgPreserve Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
Deletions:
##[[KeyPgPreserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.


Revision [13720]

Edited on 2008-09-11 13:02:36 by CountingPine [Small clarification on the fixed-size array issue]
Additions:
##//subscript//##: [ ##//lowerbound// To## ] ##//upperbound//##
##[[KeyPgPreserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
- ##**Redim**## cannot be used on fixed-size arrays, i.e. arrays with constant bounds. This includes arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs.
Deletions:
##//subscript//##: [ ##//lowerbound//## TO ] ##//upperbound//##
##**Redim** [[KeyPgPreserve Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
- ##**Redim**## cannot be used on arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs.


Revision [13719]

Edited on 2008-09-11 12:55:38 by CountingPine [Reformat notes]
Additions:
**NOTES**:
- ##**Redim** [[KeyPgPreserve Preserve]]## may not work as expected in all cases:
##**Redim** [[KeyPgPreserve Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
Its behavior is only well-defined when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
If there are multiple dimensions, only the upper bound of the first dimension may be changed safely. If lower-order dimensions are resized at all, the effects can be hard to predict.
- ##**Redim**## cannot be used on arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs.
- Using ##**Redim**## within a member procedure with an array that contains an instance of the object class is undefined, and will [hopefully] result in horrible crashes.
Deletions:
Note: ##**Redim** [[KeyPgPreserve Preserve]]## may not work as expected in all cases.
##**Redim** [[KeyPgPreserve Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
Its behavior is only well-defined when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
If there are multiple dimensions, only the upper bound of the first dimension may be changed safely. If lower-order dimensions are resized at all, the effects can be hard to predict.
##**Redim**## cannot be used on arrays contained in UDTs (user-defined ##[[KeyPgType Type]]##s), because currently only fixed-size arrays are supported in UDTs.
**NOTE**: Using ##**Redim**## within a member procedure with an array that contains an instance of the object class is undefined, and will [hopefully] result in horrible crashes.


Revision [13693]

Edited on 2008-09-07 08:30:09 by JeffMarshall [name case fixup]
Additions:
The lower and upper bound range for a dimension of the array. Lower bound defaults to zero (##0##), or the default ##[[KeyPgOptionbase Base]]##, if not specified.
Deletions:
The lower and upper bound range for a dimension of the array. Lower bound defaults to zero (##0##), or the default ##[[KeyPgOptionBase Base]]##, if not specified.


Revision [13654]

Edited on 2008-08-22 16:56:38 by CountingPine [Elaborate on where Redim Preserve can be used safely]
Additions:
When used with an existing array, the contents of the array will be preserved during the resize. Note that ##[[KeyPgPreserve Preserve]]## will not work properly in all cases.
The lower and upper bound range for a dimension of the array. Lower bound defaults to zero (##0##), or the default ##[[KeyPgOptionBase Base]]##, if not specified.
When defining a new variable-length array, its elements are default constructed. For simple data types like ##[[KeyPgInteger Integer]]## or ##[[KeyPgDouble Double]]##, the elements are initialized to zero (##0##). For user-defined types with a default constructor, that will be called.
Note: ##**Redim** [[KeyPgPreserve Preserve]]## may not work as expected in all cases.
##**Redim** [[KeyPgPreserve Preserve]]##'s current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory.
Its behavior is only well-defined when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound.
If there are multiple dimensions, only the upper bound of the first dimension may be changed safely. If lower-order dimensions are resized at all, the effects can be hard to predict.
ReDim array(0 To 4) As Integer
'' Resize a variable-length array with 10 elements
'' (the lower bound should be kept the same)
ReDim Preserve array(0 to 9) As Integer
This program will produce the following output:
0 0
1 1
2 2
3 3
4 4
5 5
{{fbdoc item="filename" value="examples/manual/array/redim2d.bas"}}%%(freebasic)
'' Define a variable-length array
Dim array() As Integer
'' ReDim array to have 3*4 elements
ReDim array(1 To 3, 1 To 4)
Dim As Integer n = 1, i, j
Print "3 * 4:"
Print
For i = LBound(array, 1) To UBound(array, 1)
For j = LBound(array, 2) To UBound(array, 2)
array(i, j) = n
Print Using "## "; array(i, j);
n += 1
Next
Print
Print
'' ReDim Preserve array to have 4*4 elements, preserving the contents
'' (only the first upper bound should be changed)
ReDim Preserve array(1 To 4, 1 To 4) As Integer
Print "4 * 4:"
Print
For i = LBound(array, 1) To UBound(array, 1)
For j = LBound(array, 2) To UBound(array, 2)
Print Using "## "; array(i, j);
Next
Print
Print
'' ReDim Preserve array to have 2*4 elements, preserving but trancating the contents
'' (only the first upper bound should be changed)
ReDim Preserve array(1 To 2, 1 To 4) As Integer
Print "2 * 4:"
Print
For i = LBound(array, 1) To UBound(array, 1)
For j = LBound(array, 2) To UBound(array, 2)
Print Using "## "; array(i, j);
Next
Print
Print
This program will produce the following output:
%%3 * 4:
1 2 3 4
5 6 7 8
9 10 11 12
4 * 4:
1 2 3 4
5 6 7 8
9 10 11 12
0 0 0 0
2 * 4:
1 2 3 4
5 6 7 8
- ##[[KeyPgPreserve Preserve]]## was in Visual Basic, but not in QBASIC.
- Multi-dimensional arrays in ""FreeBASIC"" are in row-major order, rather than column-major order.
Deletions:
When used with an existing array, the contents of the array will be preserved during the resize. Note that ##[[KeyPgPreserve Preserve]]## will not work with multi-dimensional arrays.
The lower and upper bound range for a dimension of the array. Lower bound defaults to zero (0) if not specified.
When defining a new variable-length array, its elements are default constructed. For simple data types like ##[[KeyPgInteger Integer]]## or ##[[KeyPgDouble Double]]##, the elements are initialized to zero (0). For user-defined types with a default constructor, that will be called.
When a variable-length array is resized without the ##[[KeyPgPreserve Preserve]]## clause, it's elements are destroyed, and new elements are default constructed. The ##[[KeyPgPreserve Preserve]]## clause does not destroy existing elements unless the new size of the variable-length array is smaller than it was previously. When resizing an array larger, the new elements are default constructed at the end of the array.
ReDim array(1 To 5) As Integer
'' Resize a variable-length array with 10 elements
ReDim Preserve array(9) As Integer
The previous program will produce the following output:
0 1
1 2
2 3
3 4
4 5
5 0
- ##[[KeyPgPreserve Preserve]]## is new to FreeBASIC.


Revision [12541]

The oldest known version of this page was created on 2008-02-06 06:58:14 by CountingPine [Elaborate on where Redim Preserve can be used safely]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode