使用临时寄存器变量 [英] Using temporary register Variable

查看:78
本文介绍了使用临时寄存器变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用一个值为临时值的变量,我不希望因性能原因而将内存转移到内存中。有没有办法指定

这样的变量,这样对变量的任何赋值都不会给内存带来
。我尝试了类型寄存器,但它似乎不起作用。

谢谢

Shankar

解决方案

< blockquote> Shankar Agarwal< sh ****** @ stanford.edu>写在

新闻:Pi ************************************* @cardi nal5.Stanford.EDU:

我试图使用一个值为临时值的变量,我不想让它为性能而去记忆原因。有没有办法像这样指定变量,以便对变量
的任何赋值都不会进入内存。我尝试了类型寄存器,但它似乎没有工作。




''register''只是一个提示,很容易被编译器忽略。唉,这是进入真实注册的唯一标准方法。

。如果事情是关键的话,汇编程序是你朋友的朋友。


-

- 马克 - >

-


问候。


文章

< Pi *** ********************************** @ cardinal5 .Stanford.EDU>,

Shankar Agarwal写道:

我试图使用一个值为临时值的变量,我不希望它出于性能原因而转到内存中。有没有办法像这样指定变量,以便对变量
的任何赋值都不会进入内存。




不,不是标准C.正如你所发现的那样,登记。说明符

只不过是对编译器的一个提示,它可以自由忽略。

(并且因为大多数现代编译器在优化代码方面远胜于

普通人,他们通常会忽略它。)你的编译器可能会给b $ b提供扩展来强制注册分配。但是,代码真的是性能至关重要吗?应始终在算法级别优化优化

;担心像

注册变量这样的小事很少值得一试。


问候,

Tristan


-

_

_V.-o Tristan Miller [en,(fr,de,ia)]><空间有限

/ |` - '' - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =<> ;在ha句中,所以很难

(7_ \\ http://www.nothingisreal.com/ ><完成你的工作




" Shankar Agarwal" ;< sh ****** @ stanford.edu>写在消息


我尝试了类型寄存器,但它似乎不起作用。



" register"只是一个提示。你可以尝试更改编译器,你可以试试改变变量的类型
,它是一个int吗?),你可以尝试简化

它所使用的函数并删除其他变量,当然这可能是不可能的。

几乎每个C编译器都带有内联汇编程序,你可能会想要诉诸于此。


I was trying to use a variable whose value is temporary and i don''t want
it to go to the memory for performance reasons. Is there a way to specify
the variable like that so that any assignment to the variable does not go
to memory. I tried the type register but it does not seem to work.
Thanks
Shankar

解决方案

Shankar Agarwal <sh******@stanford.edu> wrote in
news:Pi*************************************@cardi nal5.Stanford.EDU:

I was trying to use a variable whose value is temporary and i don''t want
it to go to the memory for performance reasons. Is there a way to
specify the variable like that so that any assignment to the variable
does not go to memory. I tried the type register but it does not seem to
work.



''register'' is just a hint, easily ignored by the compiler. Alas, this is
your only standard method to get into a real register. Assembler is your
friend if things are this critical.

--
- Mark ->
--


Greetings.

In article
<Pi*************************************@cardinal5 .Stanford.EDU>,
Shankar Agarwal wrote:

I was trying to use a variable whose value is temporary and i don''t
want it to go to the memory for performance reasons. Is there a way to
specify the variable like that so that any assignment to the variable
does not go to memory.



No, not in standard C. As you''ve discovered, the "register" specifier
is no more than a hint to the compiler, which it''s free to ignore.
(And as most modern compilers are far better at optimizing code than
the average human, they usually do ignore it.) Your compiler may
provide an extension to force register allocation. Is the code really
that performance-critical, though? Optimization should always be done
at the algorithmic level first; worrying about little things like
register variables is rarely worth one''s effort.

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-'' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it''s hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you



"Shankar Agarwal" <sh******@stanford.edu> wrote in message


I tried the type register but it does not seem to work.


"register" is only a hint. You can try changing compilers, you can try
changing the type of the variable (is it an int?), you can try simplifying
the function it is in and removing other variables, though of course this
might not be possible.
Virtually every C compiler comes with an inline assembler, and you probably
want to resort to this.


这篇关于使用临时寄存器变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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