[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: GC
- From: Asko Kauppi <askok@...>
- Date: Tue, 5 May 2009 20:46:29 +0300
I've recently done a C++/Lua binding, which is really simple,
efficient and I would say elegant.
It is based on a customized C++ 'new' operator, so pushing an object
is done as:
myobj *m= new(L) myobj();
or if the C side does not need that object, just:
Of course any constructor will be valid (here without parameters).
The object's memory is allocated from Lua stack, and __gc is bound so
that the C++ delete operator gets called automatically.
I've enjoyed using this mechanism for the customer project, and I can
ask them to release it (with MIT license) if there is interest on the
Javier Guerra kirjoitti 5.5.2009 kello 18:38:
On Tue, May 5, 2009 at 10:27 AM, Gergely BOROMISSZA
I've already read the manual but my __gc function was only called
when I quit the program or when I call collectgarbage manually. So
there was a plenty waste of memory which was not freed.
what happened was probably that the GC didn't see any need to collect.
Lua only keeps track of the memory used inside Lua. if your userdata
holds only a pointer, or a small structure with references to bigger
objects, that would be the only size that Lua knows about.
to get better results either put most of your object's data inside the
userdata, or add some close() method that releases any resource
external to Lua.