注册变量怀疑 [英] Register variables doubt

查看:60
本文介绍了注册变量怀疑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Group,


我对寄存器变量有疑问。


我知道如果我们经常使用变量一个函数,

然后提供我们从不应用&函数,我们可以将它定义为一个

寄存器变量,这将使访问速度更快。


现在问题是:显然有在我们的CPU中只有固定数量的

寄存器,可能是6或者其他什么。那么我们如何选择将哪些
变量定义为寄存器变量呢?显然像循环

计数器或经常访问的指针我们必须定义为寄存器,但

人们使用的其他标准是什么?

$ b $ ; b由于

解决方案
Vashna写道:

您好集团


我对寄存器变量有疑问。


我知道如果我们在函数中经常使用变量,

然后提供我们从不应用&函数,我们可以将它定义为一个

寄存器变量,这将使访问速度更快。


现在问题是:显然有在我们的CPU中只有固定数量的

寄存器,可能是6或者其他什么。那么我们如何选择将哪些
变量定义为寄存器变量呢?显然像循环

计数器或频繁访问的指针我们必须定义为寄存器,但

人们使用的其他标准是什么?

http://www.c-faq.com 是这个

新闻组的常见问题数据库。


您可能需要从问题20.13开始

Vashna写道:


Hi Group,


我对寄存器变量有疑问。


我知道如果我们在一个函数中经常使用一个变量,那么

然后提供我们永远不会应用&函数,我们可以将它定义为一个

寄存器变量,这将使访问速度更快。



此外,外部物品不允许使用

注册资格。


同时说明确定一个符合注册资格的对象将被更快地访问b $ b。是不正确的。编译器可以自由地忽略

限定符。


现在问题是:显然只有固定数量的

在我们的CPU中注册,可能是6或者其他什么。那么我们如何选择将哪些
变量定义为寄存器变量呢?显然像循环

计数器或频繁访问的指针我们必须定义为寄存器,但

人们使用的其他标准是什么?



大多数现代编译器程序员都不使用

all的寄存器限定符。原因是编译器的优化器几乎总是可以比程序员更好地注册分配。


>我对寄存器变量有疑问。


>
我知道如果我们在一个函数中经常使用一个变量,那么我们就不会应用&函数,我们可以将它定义为一个
寄存器变量,这将使访问速度更快。



你不应该知道它会让它变得更快,它会更快地使它变得更好,也不会让它更慢或者慢得多。

但它可能会。编译器可以完全忽略注册声明



>现在问题是:显然只有固定数量的
在我们的CPU中注册,可能是6或者其他什么。那么我们如何选择将哪些变量定义为寄存器变量呢?



我通常让编译器完成它的工作并定义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 a
register variable and this will make it much faster to access.

Now the question is: obviously there are only a fixed number of
registers in our CPU, maybe 6 or something. So how do we choose which
variables to define as register variables? Obviously things like loop
counters or frequently accessed pointers we must define as register, but
what other criteria do people use?

Thanks.

解决方案

Vashna wrote:

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 a
register variable and this will make it much faster to access.

Now the question is: obviously there are only a fixed number of
registers in our CPU, maybe 6 or something. So how do we choose which
variables to define as register variables? Obviously things like loop
counters or frequently accessed pointers we must define as register, but
what other criteria do people use?

http://www.c-faq.com is the Frequently Asked Questions database for this
newsgroup.

You probably need to start with Question 20.13


Vashna wrote:

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 a
register variable and this will make it much faster to access.

Furthermore external objects are not permitted to be qualified with
register.

Also stating with certainty that an object qualified with register will be
accessed "much faster" is not correct. The compiler is free to ignore the
qualifier.

Now the question is: obviously there are only a fixed number of
registers in our CPU, maybe 6 or something. So how do we choose which
variables to define as register variables? Obviously things like loop
counters or frequently accessed pointers we must define as register, but
what other criteria do people use?

With most modern compilers programmers do not use the register qualifier at
all. The reason is that the compiler''s optimiser is likely to almost always
to better register allocation than the programmer.


>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 a
register variable and this will make it much faster to access.

You should not know that it will make it faster, that it will make
it much faster, nor that it will make it slower or much slower.
But it might. The compiler is free to ignore the register declaration
entirely.

>Now the question is: obviously there are only a fixed number of
registers in our CPU, maybe 6 or something. So how do we choose which
variables to define as register variables?

I generally let the compiler do its job and define none. Dedicating
a register might slow down other calculations that need it more.

>Obviously things like loop
counters or frequently accessed pointers we must define as register, but
what other criteria do people use?

If you have MEASURED the performance both ways, and register improves
performance, go ahead and use it, but be prepared to MEASURE again when
moving to a different platform / compiler / OS.


这篇关于注册变量怀疑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆