Fixed Size Buffers
From RemObjects Software
This is a Oxygene Language Feature topic
Feel free to add your notes to this topic below.
In unsafe code blocks, it's possible to declare fixed-size structures containing embedded arrays.
The arrays are placed inline and they can only be defined inside a class or record as a field or as a local variable:
type myrec = record chars: inline array[0..255] of char; ints: inline array[1..5,1..9] of integer; end;
Note: if the code above does not compile ('Unsafe code not allowed'), you will need to adjust the project option allowing unsafe code.
Rules
The following rules apply to inline arrays:
- they cannot be used as regular types
- they must be declared within an unsafe method
- they can have multiple dimensions but the dimensions all have to be defined (unlike regular arrays)
- the subtype must be one of : smallint, shortint, integer(longint), int64, byte, word, cardinal(longword), uint64, double, single, boolean, char
Example
type Counts = record Squares: inline array[1..20] of integer; Cubes: inline array[1..20] of integer; end; MainForm = class(System.Windows.Forms.Form) public constructor Create; class method Main; method Test; unsafe; end; implementation method MainForm.Test; var c: Counts; i: Integer; begin for i := 1 to 20 do begin c.Squares[i] := i*i; c.Cubes[i] := i*c.Squares[i]; end; end;
See Also
Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0
Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)
Glossary — Keywords — Language Features — Platform Features — Samples — Articles — How To — Issues
Categories: Text | Oxygene | Feature
