electroRF
Member
Hi,
I write this thread here as I suspect that it is Hardware that stands behind memroy alignment.
I read in several places that most CPUs place objects / variables in paritcular offsets in memory.
for 32-bit CPUs, all objects / variables will be located in addresses that are divisable by 4 Bytes - i.e. 0x0000, 0x0004, ... 0x0020, ....
additionally, if user defines a struct which is 18-byte large, the CPU will pad it up with 2-extra bytes, to make it 20-byte large (without the user noticing the difference).
What is the reason behind it?
I understand that if 32-bit CPU can interface only memory addresses in 4-byte offset, then for reading data from address 0x0007, it'd need to read data from 0x0004, and make << 3 shift operation, which will slow its performance.
but why can't it start reading from address 0x0007?
Additionally, is it correct to say that 8-bit CPUs don't have to deal with memory alignment, as they can access any address in the memory? (as their word size is 1-byte).
Thank you very much.
I write this thread here as I suspect that it is Hardware that stands behind memroy alignment.
I read in several places that most CPUs place objects / variables in paritcular offsets in memory.
for 32-bit CPUs, all objects / variables will be located in addresses that are divisable by 4 Bytes - i.e. 0x0000, 0x0004, ... 0x0020, ....
additionally, if user defines a struct which is 18-byte large, the CPU will pad it up with 2-extra bytes, to make it 20-byte large (without the user noticing the difference).
What is the reason behind it?
I understand that if 32-bit CPU can interface only memory addresses in 4-byte offset, then for reading data from address 0x0007, it'd need to read data from 0x0004, and make << 3 shift operation, which will slow its performance.
but why can't it start reading from address 0x0007?
Additionally, is it correct to say that 8-bit CPUs don't have to deal with memory alignment, as they can access any address in the memory? (as their word size is 1-byte).
Thank you very much.