[fpc-devel] Aligned dynamic arrays

Anthony Walter sysrpl at gmail.com
Sat Mar 30 14:39:01 CET 2019


1) In you example you are writing this with normal arrays:

A[0].X := 0;

And in my implementation it's exactly the same. Regarding writing the
entire type directly

A[0]^ := V;

If using the caret symbol ^ or an Item property is a deal breaker, then
this can be simplified using a custom smart pointer type similar to how the
aligned array type was implemented resulting in the same syntax as in the
first example.

2) As I've implemented them aligned array is compatible with dynamic
arrays. They implicitly convert between the two with no loss of data. If
you truly want to share the data within each, then you can define functions
to work on referencing the data types they hold, allowing the same function
to serve either type.

For example:

procedure VectorTransform(Matrix: TMat4; FirstVertex: PVec3; Count:
Integer);

and then

Matrix.Rotate(12.5, 0, 0);
VectorTransform(Matrix, AlignedData[0], AlignedData.Length);
VectorTransform(Matrix, @DynamicArray[0], Length(AlignedData));

Or you can even overload VectorTransform if you don't want to see @
symbols.

procedure VectorTransform(Matrix: TMat4; FirstVertex: var TVec3; Count:
Integer); overload;

3) Regarding Hi, Lo, Length, I prefer to put these functions on types. For
example

for I := A.Lo to A.Hi do A[I].X := I;

Is that such a deal breaker?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190330/d13c4762/attachment.html>


More information about the fpc-devel mailing list