lua-users home
lua-l archive

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


On Fri, Oct 28, 2022 at 6:12 AM bil til <biltil52@gmail.com> wrote:

> Therefore I would like to handle them similar like FileIO objects in
> liolib.c with meta functions read/write/open... (but per IO only a
> very small userdata necessary, typically only 1-2 int's or so...).

[...]

> If I give meta support to such userdata IOports (opened the standard
> way with lua_newuserdatauv), then how much bytes will be consumed by
> this "meta addition" to each object?

I must admit that I do not fully understand what your question really
is about. This may be because you make some wrong assumptions in your
question.

Every userdatum has the same "header" structure, which has a pointer
to a metatable. It is there even if the metatable is not used.

Typically, all userdata of a single "kind" would point to one and the
same metatable, so the cost  of having the metatable is exactly ONE
metatable for all those userdata. Note you do not have to use a string
to label the metatable, even though some Lua API expects that.

The above-mentioned header is in itself quite big, several times
bigger than the 1-2 ints that you mentioned. So a 64K system could
host about 1K userdata in total, and probably much fewer when it does
something useful.

Cheers,
V.