<HTML>
<div><style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>Just to add a minor thing... while usually you don't have to align memory any more coarsely than 16 bytes for XMM, 32 bytes for YMM and 64 bytes for ZMM, the 4 kB granularity is useful for paging, especially if you're reading or writing to a swap file. An entire library of functions for such memory management and alignment would definitely be beneficial. Using FastMM4 if at all possible is even better.</div><div><br>
</div><div>And that record definition is pretty nice, I have to say!</div><br>
Gareth aka. Kit<br>
<br>
<br>
<br>
<span style="font-weight: bold;">On Thu 28/03/19 22:40 , Anthony Walter sysrpl@gmail.com sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT:0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"><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.</t></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>
</t></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>;</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.</t></div></div></div></div>
_______________________________________________<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a><br>
<a target="_blank" href="<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span></a><br>
<br>
</blockquote></HTML>