[fpc-devel] Aligned dynamic arrays

Anthony Walter sysrpl at gmail.com
Fri Mar 29 06:01:27 CET 2019


Here is the full implementation of aligned arrays, let me know if it works
for you.

https://www.getlazarus.org/arrays/

Here is another example:

uses
  AlignArrays;

procedure Test;
var
  VertexData: TAlignedArray<TVec3>;
  V: PVec3;
  I: Integer;
begin
  VertexData.Length := 100; // page sized and aligned memory allocated here
  V := VertexData[0]; // get a reference to the first item
  for I := 0 to V.Length - 1 do
  begin
    V^ := ComputeVertex(I); // write to vertex data faster via a pointer
    Inc(V);
  end;
  for V in VertexData do // array like enumerators are supported
    PrintVertex(V);
  V.Item[6] := ComputeVertex(Random(100)); // you can write directly using
this syntax
  V[7]^ := ComputeVertex(Random(100)); // or write by dereferencing  the
default indexer
end; // there is no need to free the memory, it is taken care of for you by
finalize
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190329/d28bb367/attachment.html>


More information about the fpc-devel mailing list