Fixed Size Buffers

From The Oxygene Language Wiki

Jump to:navigation, search

This is a Language 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:


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


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox