[fpc-devel] Aligned dynamic arrays

J. Gareth Moreton gareth at moreton-family.com
Fri Mar 29 09:06:26 CET 2019


 I wonder if there's any incentive to have such a feature in-built in the
compiler.  The bounty on #34031 has probably expired by now.  If not,
then your unit would be a great addition.
 Page-aligned memory is probably something that warrants further discussion
with the core team.

 Gareth aka. Kit

 On Fri 29/03/19 05:01 , "Anthony Walter" sysrpl at gmail.com sent:
 Here is the full implementation of aligned arrays, let me know if it works
for you.
 https://www.getlazarus.org/arrays/ [1]

 Here is another example:
 uses  AlignArrays;
  procedure Test;var
   VertexData: TAlignedArray;  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
  

Links:
------
[1] https://www.getlazarus.org/arrays/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190329/ef9af4f2/attachment.html>


More information about the fpc-devel mailing list