lua-users home
lua-l archive

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


On Tuesday, April 22, 2014 04:11:43 PM Ross Bencina wrote:
> My use-case involves a large amount of these light userdata, so "only"
> adding overhead to each userdata can also be a problem.

The distinction I made was adding overhead only on userdata versus the 
overhead of storing an extra field in every value.

A weak table adds slightly more time cost, as you point out, but with a much 
lower size cost. Particularly when the feature is not being used. How much 
time does your program spend checking the types of pointers?

The other alternative, which has a similar cost to a weak table, is to use 
full userdata. The Peng proposal discarded this based on the assumption that 
each unique pointer type would need its own metatable. That doesn't have to be 
the case. A single metatable can be used for all managed pointers if the 
userdata boxes the pointer and the type.

    typedef struct { void * p; int t; } typedpointer;
    if ((typedpointer)lua_touserdata(L, 1)->t == TYPE) {}


Summary of my argument: how can you say full userdata is wasteful, then 
propose to increase the size of every value?

-- 
tom <telliamed@whoopdedo.org>