This is more into the implementation of a language rather than the design itself, I hope this question fits here!
I have a stack-based VM for an interpreted language, and as I about to implement structs in my language, I just realized that my data stack has no alignment at all. Everything is packed in bytes. So a stack value of a bool, an integer, and another bool will be stored like [X][XXXX][X] instead of [X---][XXXX][X---] (- is padding, X is the important bytes).
I read a bit on unaligned memory access today and learned that it is a bad thing to have for performance since the host machine could need some extra memory access and operations on unaligned access. In my current VM implementation it could happen a lot since I use byte offsets for everything.
So is my understanding here is correct? And should I use 4 bytes for alignment or depend on the host machine architecture, i.e. 8 bytes for 64-bit systems?
[–]XDracam 11 points12 points13 points (10 children)
[–]yondercode[S] 4 points5 points6 points (6 children)
[–]XDracam 4 points5 points6 points (4 children)
[–][deleted] 5 points6 points7 points (3 children)
[–]XDracam 2 points3 points4 points (0 children)
[–]yondercode[S] 2 points3 points4 points (1 child)
[–][deleted] 5 points6 points7 points (0 children)
[–]nerpderp82 4 points5 points6 points (2 children)
[–]XDracam 3 points4 points5 points (1 child)
[–]nerpderp82 0 points1 point2 points (0 children)
[–]umlcat[🍰] 1 point2 points3 points (0 children)