lua-users home
lua-l archive

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


在 2017/3/21 2:26, Tim Hill 写道:
>
>> On Mar 19, 2017, at 8:55 PM, 云风 Cloud Wu <cloudwu@gmail.com <mailto:cloudwu@gmail.com>> wrote:
>>
>>
>> Tim Hill <drtimhill@gmail.com <mailto:drtimhill@gmail.com>>于2017年3月20日周一 上午11:12写道:
>>
>
> But a light userdata with a metatable basically *IS* a full userdata. The only difference is that the full userdata is allocated by Lua, and undergoes garbage collection .. which you ALSO want for the __gc. As you noted, the technique here is to allocate a full userdata that just holds a C pointer (aka a light userdata).
>
> Your request won’t get you a lower overhead .. it will just get you something else that is identical to full userdata but with a different name.
>
> —Tim
>


one major difference between light- and full- userdata is the equality test.

light userdata is tested by value while full userdata is tested by reference.

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

-- 
the nerdy Peng / 书呆彭 /