<div dir="ltr"><div dir="ltr"><div dir="ltr">Here is a brief follow up. I am working on other projects at the moment, but I am confident this a simple solution. Please tell me if this somehow will not fit you needs.<div><br></div><div>Create a new type that is compatible with Array<T> where Array<T> = type array of T.</div><div>Define implcit conversions between the to types and similar methods</div><div>Create a Push and Pop methods, well as a read write Length property and two indexers.</div><div>Indexer named Reference is default and provides a memory reference to Tn</div><div>Indexer named Item is available and provides a copy of Tn<br></div><div><br></div><div>So we would have ...</div><div><br></div><div>  TAlignedArray = record<T><br></div><div>    type TReference = ^T;</div><div>    type TValue = T;</div><div>    FPage: Pointer;</div><div>    FLength: Integer;</div><div>    procedure SetLength(Value: Integer);</div><div>    function GetReference(Index: Integer): TReference;</div><div>    function GetItem(Index: Integer): TValue;</div><div>    procedure SetItem(Index: Integer; const Value: TValue);</div><div>  public</div><div>    procedure Push(const Item: TValue);</div><div>    procedure Pop: TValue;</div><div>    property Length: Integer read FLength write SetLength;</div><div>    property Reference[Index: Integer]: TValue read GetReference; default;</div><div>    property Item[Index: Integer]: TValue read GetValue write SetValue;</div><div><br></div><div>Examples usages:</div><div><br></div><div>type</div><div>  TVertexArray = TAlignedArray<TVec3>;</div><div><br></div><div>// and later</div><div><br></div><div>var</div><div>  Vertices: TVertexArray;</div><div>begin<br></div><div>  Vertices.Length = 1000; // okay, request a page aligned memory</div><div>  Vertices[0].X := X; // okay, we are working with references</div><div>  Vertices.Item[1] := Vec3(X, Y, Z); // okay, we are setting a value</div><div>  Vertices.Length = 0; // clean up<br></div><div><br></div><div><br></div><div>When the vertex array need to grow, it uses the POSIX posix_memalign (or the _aligned_malloc on Windows) to request a 4 KB aligned and sized page adequate to contain all the items. The newish allocate and release mechanisms can further be used to simply the management of the TAlignedArray<T> type.</div></div></div></div>