Samsung Interview Question
Software Engineer / DevelopersTeam: networking
Country: India
Interview Type: In-Person
Memory alignment is not really compiler specific, but it is rather architecture specific, but having said that your compiler is arch. specific. Architecture suggests compiler writer about how memory usage can be optimized, so compiler writer kinda follows it. On intel processors, for 32 bit processors this alignment is 16bytes. This way architecture tells: I am comfortable moving 16bytes chunk from one place to other.
this can be tested very easily. Simply convert following code into assembly language.
int main()
{
int a = 10;
int b = a+5;
return 0;
}
Your compiler needs to match the code alignment (RAM word size) of the instructions it is processing with the OS / CPU's specific RAM implementation on the hardware the compiler is targeting.
- ablarg September 14, 2014