lua-users home
lua-l archive

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


Hello Luiz,

Sunday, December 10, 2006, 2:14:41 AM, you wrote:

>> Can you guarantee this will not be changed in future version of lua ?

LHdF> No, but we have no plans for a moving garbage collector.

>> I have another question.
>> When I use lua_newuserdata(or lua_touserdata) to get a pointer to the
>> memory , can I save it in my C struct directly? or I should use
>> lua_tousedata to convert the userdata to a pointer every time I need ?

LHdF> If you can guarantee that the memory is not collected, then yes you can
LHdF> store the pointer. But remember that memory allocated via lua_newuserdata
LHdF> is subject to garbage collection.

We can put userdata A into a table, and then set this table as
userdata B's environment.

If userdata B doesn't be collected, the userdata A must not be
collected . And then we can store the userdata A's pointer in the userdata
B safety now.

The only thing I worried about is moving garbage collector may change the
userdata's pointer. Or you can add a new meta method "moving" to a
userdata, if you have plans for a moving garbage collector :)


-- 
Best regards,
 Cloud                            mailto:cloudwu@163.com
            http://blog.codingnow.com

[学问二字, 须要拆开看, 学是学, 问是问]