lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 10/23/2016 9:28 AM, Marc Balmer wrote:
Hi all. 

I want to avoid any unnecessary table creation to keep the gc workload low. 

Question: will the following code create the new table "{}" only if the 
parameter "tbl" is nil

yes.

OR will the new table created always and garbage 
collected if the parameter "tbl" is given? 

no.



---8<---------------------------- 
function xx(tbl) 
local todolist = tbl or {}; 
... 
end; 
---8<---------------------------- 

tia. 

Ulrich Schmidt 


This is very slightly incorrect. This code will also create a table if "tbl" is false. This is probably not that important to your use case.

-- Mike Nelson