lua-users home
lua-l archive

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

Hi all,
I'm pretty new to Lua but not new to scripting in general, so I was wondering how Lua uses memory regarding "tables", "userdata" and userdata-in-tables.
Let me clear the question with an example. Say Lua is getting C++ classes through the userdata mechanism, and that this same userdata "travels" (gets referenced) in many different tables throughout the scripts...would the memory be consumed by such a behavior ?
(I've read userdata is basically a it shouldn't...)

mytable = {}
mytable.class = CPP_Class()  -- creates a new class object in Lua and stores in a Lua table.

-- issue 1:
mytable2 = {}
mytable2 = mytable               -- is the userdata in .class only referenced or "copied", thus consuming more memory ?

--issue 2:
mytable3 = {}
mytable3.class = mytable.class
mytable3.table1 = mytable
mytable3.table2 = mytable2

At this point I have like 5 references of CPP_Class in tables members. Does it take 5 times the memory for the class or not ?

Thank you for any answer.