Revision [11945]

This is an old revision of ProPgFixLenArrays made by ElSairon on 2007-12-21 14:27:51.

 

Fixed-length Arrays


Fixed-size homogeneous data structures.

Overview
Fixed-length arrays are ProPgArrays arrays that have a fixed constant size throughout the execution of a program. The memory used by a fixed-length array to store its elements is allocated at compile-time, either on the stack or in the .BSS or .DATA sections of the executable, depending on whether KeyPgStatic Static was used to define it. This may allow for quicker program execution since the memory for the array is already allocated, unlike ProPgVarLenArrays variable-length arrays, whose element memory isn't allocated until runtime.
Fixed-length arrays with ProPgStorageClasses automatic storage, have their elements allocated on the program stack, and pointers to these elements remain valid only while the array is in scope. The elements of fixed-length arrays with ProPgStorageClasses static storage are allocated in the .DATA or .BSS sections of the executable, depending on whether or not they are initialized when defined, so pointers to these elements remain valid for the entire execution of the program. Fixed-length arrays of any storage class cannot be resized during program execution, only ProPgVarLenArrays variable-length arrays can.

Declaration and definition
A fixed-length array is declared with the KeyPgExtern Extern keyword, followed by a variable identifier, a parenthesized list of one (1) or more subscript ranges and an element CatPgStdDataTypes datatype. For an array to be declared fixed-length, either numerical literals, KeyPgConst Const variables or KeyPgEnum Enum enumerators can be used as subscript range values.

Const maxLowerBound As Integer = -5
Const maxUpperBound As Integer = 10

'' Declares a two dimensional fixed-length array of elements of type STRING..
Extern arrayOfStrings(maxLowerBound To maxUpperBound, 20) As String

'' Declares a one-dimensional fixed-length array of elements of type BYTE,
'' big enough to hold an INTEGER..
Extern arrayOfBytes(SizeOf(Integer)) As Byte
A fixed-length array is defined with either the KeyPgStatic Static or KeyPgDim Dim keywords, following the same form as declaration.

'' Defines a one-dimensional fixed-length array of type SHORT having static storage.
Static arrayOfShorts(420) As Short

'' Defines a one-dimensional fixed-length array of type INTEGER having automatic storage.
Dim arrayOfIntegers(69) As Integer


Back to Programmer's Guide
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode