CopyStructure question
Posted: Wed Mar 22, 2017 10:57 pm
Is it safe to copy a structure that contains an array, but the array is no longer the originally defined size?
My example below works, but I'm unsure if I will ever run into any memory issues.
My example below works, but I'm unsure if I will ever run into any memory issues.
Code: Select all
EnableExplicit
Structure Vector3
X.d
Y.d
Z.d
EndStructure
Structure BodyData
Handle.i
Position.Vector3
Array Vertex.Vector3(1)
EndStructure
Define.BodyData Body1
Define.BodyData Body2
ReDim Body1\Vertex(2)
Body1\Handle = 1
Body1\Position\X = 5.5
Body1\Position\Y = 2.0
Body1\Position\Z = 3.1
Body1\Vertex(1)\X = 4.9
Body1\Vertex(1)\Y = 8.0
Body1\Vertex(1)\Z = 3.4
Body1\Vertex(2)\X = 2.2
Body1\Vertex(2)\Y = 2.7
Body1\Vertex(2)\Z = 7.6
CopyStructure(@Body1, @Body2, BodyData)
Debug "Body2's Data"
Debug "Handle = " + StrD(Body2\Handle)
Debug "Position\X = " + StrD(Body2\Position\X)
Debug "Position\Y = " + StrD(Body2\Position\Y)
Debug "Position\Z = " + StrD(Body2\Position\Z)
Debug "Vertex(1)\X = " + StrD(Body2\Vertex(1)\X)
Debug "Vertex(1)\Y = " + StrD(Body2\Vertex(1)\Y)
Debug "Vertex(1)\Z = " + StrD(Body2\Vertex(1)\Z)
Debug "Vertex(2)\X = " + StrD(Body2\Vertex(2)\X)
Debug "Vertex(2)\Y = " + StrD(Body2\Vertex(2)\Y)
Debug "Vertex(2)\Z = " + StrD(Body2\Vertex(2)\Z)