[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Memory allocation for userdata
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Fri, 16 Dec 2011 07:06:40 -0200
> In a Lua binding there is the added possibility of allocating the
> required memory via lua_newuserdata.
If you can use lua_newuserdata, then by all means use it. It depends on
what library you're binding to Lua. There are two types of libraries
that use heap objects: those that create (ie allocate) the object
themselves and those that expect the user to do it. For the first type,
you use lua_newuserdata for the pointer only and you need to set up a
gc method to free or close the object. For the second type, you can use
lua_newuserdata for the complete object and there is no need to box the
pointer or for a gc method. lbc and lbn are example of the first type;
lmd5 and lrandom are examples of the second type.
See http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/ .