此外,外部物品不允许使用 注册资格。 同时说明确定一个符合注册资格的对象将被更快地访问b $ b。是不正确的。编译器可以自由地忽略 限定符。 大多数现代编译器程序员都不使用 all的寄存器限定符。原因是编译器的优化器几乎总是可以比程序员更好地注册分配。 你不应该知道它会让它变得更快,它会更快地使它变得更好,也不会让它更慢或者慢得多。 但它可能会。编译器可以完全忽略注册声明 。 我通常让编译器完成它的工作并定义none。专用 a寄存器可能会减慢其他需要更多的计算速度。 如果你已经测量了两种方式的性能,并且注册改善了b $ b性能,请继续使用它,但要准备好再次测量当 转移到不同的平台/编译器/操作系统时。 Hi Group, I have a doubt about register variables. I know that if we have a variable used very frequently in a function,then provided we never apply the & function to it, we can define it as aregister variable and this will make it much faster to access. Now the question is: obviously there are only a fixed number ofregisters in our CPU, maybe 6 or something. So how do we choose whichvariables to define as register variables? Obviously things like loopcounters or frequently accessed pointers we must define as register, butwhat other criteria do people use? Thanks. 解决方案 http://www.c-faq.com is the Frequently Asked Questions database for thisnewsgroup. You probably need to start with Question 20.13Furthermore external objects are not permitted to be qualified withregister. Also stating with certainty that an object qualified with register will beaccessed "much faster" is not correct. The compiler is free to ignore thequalifier. With most modern compilers programmers do not use the register qualifier atall. The reason is that the compiler''s optimiser is likely to almost alwaysto better register allocation than the programmer. You should not know that it will make it faster, that it will makeit much faster, nor that it will make it slower or much slower.But it might. The compiler is free to ignore the register declarationentirely. I generally let the compiler do its job and define none. Dedicatinga register might slow down other calculations that need it more. If you have MEASURED the performance both ways, and register improvesperformance, go ahead and use it, but be prepared to MEASURE again whenmoving to a different platform / compiler / OS. 这篇关于注册变量怀疑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-22 00:42