[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: when do programs set metatable?
- From: "Ariel Manzur" <puntob@...>
- Date: Fri, 8 Feb 2008 21:18:00 -0200
Most of the time (at least for me, and that's how tolua does it) all
instances of the same class share the same metatable, which always has
a __gc. If it's decided that a particular instance becomes "owned" by
lua after creation, it's registered on some table where the __gc
metamethod can search to see if it has to delete it.
Still, all instances have a __gc, so I assume if we wanted to keep
them out of atomic() we'd have to somehow add and remove __gc from the
userdatas, and take the penalty. The most common case is still that we
already know that the instance will be owned or not at the moment of
On Feb 8, 2008 12:45 PM, Roberto Ierusalimschy <email@example.com> wrote:
> More often than not, programs set the metatable of a userdata right
> after creating the userdata. Does anyone know of relevant counterexamples
> to this pattern?
> More specifically: if Lua puts a cost on setting the metatable of an
> object long after its creation (the longer the more expensive), do you
> know of programs that would be hurt?
> Yet more specifically, I am interested only in cases where the metatable
> has a __gc metamethod.
> -- Roberto