PDA

View Full Version : DLLs and arrays of vectors



tux
07-06-2005, 01:02 PM
ok, im making a procedure that needs a list of vertices. currently its defined as follows

procedure ProcedureName(const aVertices: TAVectorArray); cdecl;

where

TVector3f = array[0..2] of single;
TAffineVector = TVector3f;
TAVectorArray = Array of TAffineVector;

and im doing

for LLoop := 0 to High(aVertices) -1 do


if another language (say c++) uses this procedure, it wont work will it?

so i have to have size of array and the stride of each vertex?

ive *used* procedures before that use that method but i wouldnt be sure what to do with the stride with copying the data to a buffer. any ideas?




the procedure i used before is defined as follows

function NewtonCreateConvexHull( const newtonWorld : PNewtonWorld; count : int; vertexCloud : PFloat; strideInBytes : int; offsetMatrix : PFloat) : PNewtonCollision; cdecl;

where

Float = Single;
PFloat = ^Float;
Int = Integer;

savage
07-06-2005, 01:16 PM
can't really help much, but just thought I would point out that your for loop should be


for LLoop := 0 to High(aVertices) do


The -1 is not needed unless you specifically want it to stop before the last item.

{MSX}
07-06-2005, 05:00 PM
well passing dynamic arrays in and out dlls is not a good thing :P

In this case you should stay as plain as possible, but you don't need stride. Stride is needed if you have useful data interleaved with unuseful.

Just declare a pointer instead of an array, and pass the size along:


PAffineVector=^TAffineVector;

procedure ProcedureName(aVertices: PAffineVector; size:integer); cdecl;

Then inside the procedure you can fetch "size" vertices out of the pointer. You can both cast the pointer as a fake array or increment it (i don't remember if typed pointers support inc() or if you need to do that manually).

BTW i usually access dynamic arrays size with "length(array)". I think this is the official way.

tux
07-06-2005, 06:19 PM
thanks

savage
07-06-2005, 06:58 PM
"length(array)". I think this is the official way.

When using length() with arrays, then you do need to use - 1, because the length given is 1 based, but when using High() that is not needed.

BenBE
21-06-2005, 05:04 AM
Typed pointers are INCed by the size of the underlaying type. For dynamic record types this might be a bit confusing as they are as big as the largest subpart of them.