lua-users home
lua-l archive

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



On 16-May-05, at 5:01 PM, Mark Hamburg wrote:

Interesting...

One could combine this with the weak table approach by setting a weak table as the __index table for the registry. That way, when you wanted to keep the
object alive for reasons outside of Lua, you would put it in the main
registry. If that reference went away, however, you could still get to it
via the weak table backing up the registry.

Theoretically, you shouldn't need the weak table, but this would allow
member functions to push "this" to the stack without worrying about whether they could use a pre-existing stack entry for the userdata. I'm thinking
about whether that's actually an issue in practice.

That's a cool idea. You could even stash a reference count in the userdata before the actual object itself, and then let Lua do all the memory management (aside from maintaining the reference count, of course). That would allow a standard memory management regime for both shared objects and objects only referenced by Lua.

I'd use a fully-weak table rather than a weak-valued table; it would have much less impact on gc.