lua-users home
lua-l archive

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


On Thu, Mar 23, 2017 at 11:03 AM, 彭 书呆 <nerditation@outlook.com> wrote:

> this make big difference when you need to use them as table keys.

Like Tim, I fail to see any real difference here.

What is different is the allocation strategy. With light userdata, the host program has full control over memory allocation. With full userdata, it is fully[*] controlled by Lua. In the light case, not only is the host program solely responsible for memory allocation (and deallocation), it also gets no indication from Lua that a given userdatum is accessible in Lua (or not).

As consequence, I cannot use a custom allocator for a particular user data type, because it will be either unsafe (light userdata) or unusable (full userdata).

[*] I am aware that finalizers can decide whether memory is deallocated. I am talking about how memory gets deallocated, in the context of allocators customised for a particular data type.

Cheers,
V.