开发者

Is memory aligned access faster?

Suppose that my machine word is 32 bits long, and I have to sort 8-character strings.

I've read that if you pack the characters into words, the comparisons will be faster since you use aligned memory access.

So in our case, we will divide the strings into two words of 4 bytes, and use the first word of each string to compare, if they happen to be equal, then you check the second word of each string.

Does performance improve? Does it get any faster? Since coding gets more complex, does it pay off? And开发者_Go百科 if it works, does it work for all languages?


The answer is architecture dependent, and compilers usually do a pretty good job on optimizing these things. Unless you are programming for a specific architecture, needs to squeeze out every bit of speed and really know the processor, you'd better let the compiler decide the alignment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜