简体   繁体   English

Lua用户数据对齐

[英]Lua userdata alignment

How does lua_newuserdata align the allocated memory? lua_newuserdata如何对齐分配的内存? Does it depend on malloc/calloc, or does it do it's own thing? 它依赖于malloc / calloc还是自己做的? Is there any way to guarantee alignment without having to add code for this? 有什么方法可以保证对齐而不必为此添加代码?

Writing alignment code myself isn't a problem, but if it's not needed then I'd rather not, of course. 自己编写对齐代码不是问题,但是如果不需要,那么我当然不会。

All memory allocation in Lua is done throughout a user-supplied allocator given when you create a state with lua_newstate . 当您使用lua_newstate创建状态时,Lua中的所有内存分配都是在用户提供的整个分配器中 lua_newstate

If you use luaL_newstate instead of lua_newstate , then Lua uses a memory allocator based on realloc . 如果您使用luaL_newstate而不是lua_newstate ,那么Lua将使用基于realloc的内存分配器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM