[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Callbacks, upvalues and memory management
- From: Mark Hamburg <mark@...>
- Date: Sat, 30 Jul 2011 12:34:53 -0700
On Jul 30, 2011, at 11:01 AM, Gregory Bonik wrote:
> Thanks a lot, it sounds like a solution. However, I don't like tracking
> these transitions, so I came up with an idea of something like garbage
> collection.
>
> I could create a fully strong (sic!) table in the registry, let's call
> it "objects table", and store there a map between C++ objects (as light
> userdata) and their full userdatas (which will be guaranteed to be
> unique per object). Callbacks can be stored in the userdata's env table.
>
> Periodically, a "garbage collection" procedure is triggered. It
> traverses the objects table. All objects in the table with reference
> count equal to 1 are removed from the table.
>
> When an object with reference count equal to 1 is pushed from Lua to C++
> function, it is added back to the objects table.
This is almost exactly the system that Lightroom uses. It just seemed more complicated to describe in e-mail and count on people getting right.
(My latest project is written with the provision that objects just need to be prepared for their Lua-side counterparts to go away.)
Mark
- References:
- Callbacks, upvalues and memory management, Gregory Bonik
- Re: Callbacks, upvalues and memory management, Valeriy E. Ushakov
- Re: Callbacks, upvalues and memory management, Gregory Bonik
- Re: Callbacks, upvalues and memory management, Gaspard Bucher
- Re: Callbacks, upvalues and memory management, Mark Hamburg
- Re: Callbacks, upvalues and memory management, Gregory Bonik