lua-users home
lua-l archive

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


On Fri, Apr 6, 2012 at 03:12, Miles Bader <miles@gnu.org> wrote:
> 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.
>

A boxed pointer, in other words. I don't know of any other method to
deal with C++ objects that expect the use of new and delete.

-- 
Sent from my toaster.