Re: Unaligned memory access

Gé Weijers <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <CAGj8priC7qu-TYG28x4orOXnVbGTSi1uRa2ELW_MDHOyLVdWAg@mail.gmail.com>
On Sat, Feb 14, 2026 at 9:39 AM Roberto Ierusalimschy <
[email protected]> wrote:

>
> Lua ensures that the memory in a userdata is aligned with values
> in ISO C. If you have other objects that require other alignments
> (such as 16-bit values), you can redefine the macro LUAI_MAXALIGN, in
> luaconf.h. Its standard definition is like this:
>
>   #define LUAI_MAXALIGN  lua_Number n; double u; void *s; lua_Integer i;
> long l
>
> Just toss these other objects in this list.
>

This assumes that 'realloc' returns memory aligned on 16-byte boundaries. I
don't think that's guaranteed by the standard, at least I could not find it
in the C23 one.

I would replace the standard Lua allocator with one that when it creates a
uservalue uses the (post-C89) 'aligned_alloc' function or whatever the
system provides
to create a properly aligned object. And of course you'd still have to add
one of those Intel-specific types to LUAI_MAXALIGN.


-- 
Gé

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/CAGj8priC7qu-TYG28x4orOXnVbGTSi1uRa2ELW_MDHOyLVdWAg%40mail.gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.