C/C++ ---- 006

胡说之

Moderator
注册
2002-01-17
消息
5,182
荣誉分数
6
声望点数
0
What is Memory Alignment?

这个问题我心里有一个答案.共餐党员从来不隐瞒自己的观点,但是今天我不说.请大家畅所欲言.
 
就好象农村铡草一样,假如草都码得整整齐齐地,就很快.如果没码齐,总要有些草碰上边界,要调整一下带来一点延迟,那就慢了. 
 
easy

If you have two mem chips on MB, switch them -- one in slot 1 plugs into slot 2, and 2 to 1.
Since one in slot 1 could be used very frequently, but slot 2 could not.
 
最初由 胡说之 发布
用中文回答,0分

用中文批改,罚80分 :D

帅姐的答案正确,不过要是码得不齐,有的草垛可以对付。有的草垛就一定得花工夫调整。若是忘了调整,那草垛可就塌了。
 
My 2 cents:

It's an issue related to acient C compilers. If a program contains bit-wise memory space allocation without alignment, ie the reserved memory is not multiples of byte, the program may collap. However, I think this problem is not there anymore, modern compilers can make adjustment automatically in such circumstance.
 
最初由 胡说之 发布

However, I think this problem is not there anymore, modern compilers can make adjustment automatically in such circumstance.

Not really. Compiler makes it easy, but can't fully solve the problem.

C have a wonderful thing called "pointer" :) Messing arround pointer could easilier causing non-alignment access.

Non-alignment access could easily be seen on network programing, when you passing data cross network, you can't assume the other application is also compiled the same way.

Also, the compiler adjustment is OK, but when sizeof(struct abc) is not the same as sizeof(abc.member_a) + sizeof(abc.member_b), some application got angry :-)
 
后退
顶部