lua-users home
lua-l archive

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

> However, I'm a bit worried by the description of lua_pushusertag. This says
> that it first searches for a userdata with the same value and tag. The
> natural way to store ints is "unboxed", i.e. to cast them to void *, but
> this means that each time a C program wants to push an integer, the Lua
> runtime will search to see if that integer is already in use.

This search uses a hash table, and so it is not so slow. I guess the 
overhead of this search is comparable with the basic overhead of function
calls through the API (which you cannot avoid). 

> 1. How best to implement separate integer support? (Or is it just not worth
> it?)

Integers implemented through the official API will for sure be much slower 
than the native number type. Only the time for a function call (to run the 
tag method) is much larger than the time for an arithmetic opcode. What I 
think it is worth is to implement a library for "big integers". Those are
naturally unboxed, do not fit into a double, and pay for the performance.

-- Roberto