lua-users home
lua-l archive

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


Miles Bader <miles@gnu.org> writes:
> Each call to "pos" will allocate a small userdata object, which is not
> referenced by anything -- pure garbage!

BTW, I should note that the way SWIG allocates objects like this is to
use C++ "new" to create the actual object, and then allocate a Lua
userdata containing a pointer to the C++ object, some info about its
type, and a Lua metatable with a __gc entry that does the deallocation.

I don't think it's particularly efficient for small objects like this,
but as far I can tell it does the right thing, and the userdata in
this case is about the same size as the referenced data, so Lua's GC
should have roughly the right idea of how much memory is being used.

-Miles

-- 
Cat is power.  Cat is peace.