Code: Select all
Procedure FuncA(*arg.Struct)
Protected localArg.Struct
CopyStructure(*a,@localArg,SizeOf(Struct))
...
EndProcedure
Passing pointers is optimal for performance but adds a level of optimization which which is dangerous and often unnecessary. Note that resources will need to be tracked or copied in the event that data is passed on to threads or leaves scope which often makes this optimization redundant.
Pass-by-value is much simpler for these scenarios and the intent is clear. You are asking for and will receive a copy with a known lifetime as it will exist on the stack. (Note that collections contained therein are references on the heap but this requires its own consideration):
Code: Select all
Procedure FuncA(arg.Struct)
...
EndProcedure
Code: Select all
Structure Struct
value.i
EndStructure
a.Struct
a\value=123
b.Struct
b=a
Debug b\value
Code: Select all
Structure Struct
value.i
EndStructure
Procedure FuncA(*a.Struct)
*a\value=123
EndProcedure
a.Struct
FuncA(@a)
Debug a\value
Code: Select all
Structure Struct
value.i
EndStructure
Procedure.i FuncA()
Protected *a.Struct
*a=AllocateStructure(Struct)
*a\value=123
ProcedureReturn *a
EndProcedure
*a.Struct=FuncA()
Debug *a\value
FreeStructure(*a)
Code: Select all
Structure Struct
value.i
EndStructure
Procedure.Struct FuncA()
Protected a.Struct
a\value=123
ProcedureReturn a
EndProcedure
Debug FuncA()\value
Code: Select all
Procedure.Struct FuncA()
ProcedureReturn FuncB(1, 2, 3)
EndProcedure