Just ran into this and thought it might be helpful to pass it on.
This makes sense really because i think it would be copying the entire array on an off the stack.
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
type t1
x as float
y as float
z as float
endtype
global t1 as t1[]
elapsed1 as float
elapsed2 as float
print("Pass and return an array 2000 iterations")
sync()
ResetTimer()
for i=0 to 2000
t1 = PassAnArray(t1)
next
elapsed1 = Timer()
print("Dont pass an array 2000 iterations")
sync()
t1.length = -1
ResetTimer()
for i=0 to 2000
DontPassAnArray()
next
elapsed2 = Timer()
do
Print( str(ScreenFPS())+" Pass Array="+str(elapsed1)+" Dont Pass Array="+str(elapsed2) )
Sync()
loop
function PassAnArray(t1 as t1[])
t as t1
t.x = random()
t.y = random()
t.z = random()
t1.insert(t)
endfunction t1
function DontPassAnArray()
t as t1
t.x = random()
t.y = random()
t.z = random()
t1.insert(t)
endfunction