So I was reading few articles (and few questions on StackOverflow) about memory alignment and I understood why structs like this:
struct A
{
char c;
int i;
}
will have padding. Also it is clear that fetches from not aligned memory will be slower if processor can read only from aligned offsets.
But why processor can read only from aligned memory? Why it can't just read data from random address? You know, from Random-Access Memory...
I depends upon the processor. Some processors do not allow unaligned accesses at all. Other processors can, but it tends to be slower.
In your example (if the fields are packed and unaligned access it permitted, if the processor tries to read i, it usually takes fetches from memory to get it.
Some processors take the performance hit of multiple accesses to retrieve unaligned data. Others simply do not allow it.