lua-users home
lua-l archive

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


> > > 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?
> >
> > What thoughts are behind this question?  I'm curious.
> 
> I'm guessing it involves an idea for optimization.

Yes. The point would be to avoid traversing all userdata, looking
for the ones that need finalization, at the atomic phase of each GC
cycle. We could keep them (the userdata that need finalization) in
a different list.

To add another "next" pointer to each userdata would increase memory
consumption, so one way to add userdata to a diferent list is to remove
them from the rootgc list. Because this list is singled linked, Lua
should have to search the userdata from the beginning of the list to
remove it.  If it was created recently, it would be near the beginning
(probably the first one yet), so the search would be cheap.

Among other things, this change could open the doors for __gc
metamethods for tables.

-- Roberto