table.extend() to add two or more array tables without requiring extra temporary memory.
SuzannaLinn Resident
A way to add two or more array tables without requiring extra temporary memory.
table.extend(t1, t2)
Appends all elements of array t2 to the end of array t1 The array t2 is cleared and its memory released. Elements are moved directly to avoid intermediate duplication.
Working like this, but without using extra memory during the process:
extend(t1, t2)
table.move(t2, 1, #t2, #t1 + 1, t1)
table.clear(t2) -- but without preserving the allocated space
return t1
end
or better:
table.extend(t1, ...)
Appends the elements of each additional array to the end of array t1, in the order provided. The source arrays are cleared and their memory released. Elements are moved directly to avoid intermediate duplication.
Log In