lua-users home
lua-l archive

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


Thank you for taking the time to respond to my question.

>osize is any of LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION,
>LUA_TUSERDATA, or LUA_TTHREAD when (and only when) Lua is creating a
>new object of that type. When osize is some other value, Lua is
>allocating memory for something else.

I see.
Osize has not been used in the l_alloc() function.
So I think it's no meaning to pass such arguments(i.e. LUA_TSTRING,
LUA_TTABLE, LUA_TFUNCTION) to it.
Am I missing something?

Here is the related code snippet for default memory management function for Lua:
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
  (void)ud; (void)osize;  /* not used */
...
}

Thank you for your attention to this matter.

On Thu, Aug 13, 2020 at 11:35 AM 云风 Cloud Wu <cloudwu@gmail.com> wrote:
>
> 孙世龙 sunshilong <sunshilong369@gmail.com> 于2020年8月13日周四 上午11:21写道:
> >
> > Hi, list
> >
> > Since the input argument named osize has not been used in the
> > l_alloc() function, why still pass LUA_TTHREAD to this function in
> > lua_newstate()?
>
> RTFM : http://www.lua.org/manual/5.4/manual.html#lua_Alloc
>
> When ptr is NULL, osize encodes the kind of object that Lua is
> allocating. osize is any of LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION,
> LUA_TUSERDATA, or LUA_TTHREAD when (and only when) Lua is creating a
> new object of that type. When osize is some other value, Lua is
> allocating memory for something else.