Does Glulx's @malloc allocate word aligned blocks?

#1

Does the @malloc opcode allocate a block which is word aligned? Or do we need to check the address returned and pad it ourselves?

I’m thinking in terms of the opcodes in section 2.4: Array Data. Or do they not even need aligned addresses?

(David Kinder) #2

The spec makes no mention of alignment, so there is no guarantee of word alignment from @malloc. But then again, there’s no guarantee that the Glulx memory map has any particular alignment with reference to the native computer’s memory map - it’s just a block of memory, after all.

I am sure you don’t need to worry about alignment when accessing 16 and 32 bit values with @astore, @aload etc. The spec makes no mention of this, and if you look at (for example) the Git source code, you can see that such memory accesses involve byte manipulation.

1 Like
#3

That all makes sense. The VM’s endianness won’t match most CPUs anyway, so most of the time byte manipulation is not just simplest but would be hard to best the performance of.