lua-users home
lua-l archive

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




2016-06-04 17:42 GMT+08:00 Daurnimator <quae@daurnimator.com>:
> What you're suggesting is just an optimised malloc/realloc for common
> lua object sizes.
> Lua *does* have a facility for this: you can pass a lua_Alloc to lua_newstate.
> However, it will be hard to beat your system's malloc; lots of
> research and benchmarking has (should have) gone into it.
>

Good point! thanks for remind me.

So, I could first make a special allocate function for Lua, export as lua_Alloc to see whether it's different. But I can't get correct object size outside Lua, so if it does make different, to merge code into Lua is necessary.

system's malloc/free is good at general memory maintain, but if most memory are same size (not Lua itself, Lua use many variable size objects. But my library nui's object mostly have same size), *maybe* use pool may fast, with pool, only one pointer calculate is need when allocate, and two need when free in most scene, can system's malloc fast than that?

--
regards,
Xavier Wang.