<div dir="ltr">Hi,<div><br></div><div>Instances of MemoryLayout support specifying alignment constraints. However, if the alignment is set to 1 byte for all layouts, will unaligned access work on all platforms?</div><div><br></div><div>In a short test on a Mac with Apple Silicon, unaligned access works with both native and heap segments, across 8-byte boundaries using MemorySegment.get(), MemorySegment.set(), VarHandle.get() and VarHandle.set(). And the result will likely be the same on x86 machine, independent of the operating system. But is it guaranteed to work on any operating system and any CPU architecture, even on those ones where machine instructions may not read from or write to unaligned addresses?</div><div><br></div><div>If it does not work on all platform, what would happen instead? Will it throw an exception? Could it crash the JVM? Is the behavior the same for native and heap segments?</div><div><br></div><div>While researching this topic, I kept wondering where to look for documentation about it. The only description I've found is in documentation of the MemorySegment class. It has quite a long chapter about alignment, yet it doesn't really tell why you would want to use alignment constraints in the first place and what happens if an unaligned access is made anyway, with or without alignment constraint on the layout.</div><div><br></div><div>Regards</div><div>Manuel Bleichenbacher</div><div><br></div></div>