当使用寄存器用C? [英] when to use registers in C?

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

问题描述

我有这样的事情

register unsigned int a, b, c;
int n;
for (n = 0; n < 10; ++n){
c = a + b
b = a
a = c
array[n] = c;
}

它做什么,也没关系。在code跑得快,现在是,速度较慢如果寄存器关键字被删除的方式。然而,当我在寄存器INT前N增加,实际上它运行比现在更慢,但速度比,如果没有寄存器被使用。

what it does, it doesn't matter. The code runs quickly the way it is now, slower if the register keyword is removed. However, when I add in register before int n, it actually runs slower than now, but faster than if no registers is used.

有人可以解释这样对我?谢谢你。

Can someone explain this to me? Thanks.

推荐答案

注册使编译器的提示放置变量在寄存器中,而不是存储/堆栈空间。在某些情况下,不会有足够的寄存器为每一个变量你把这个关键字就这么将它放在太多的变量可以再次迫使一些其他的出寄存器。

register gives the compiler a hint to place the variable in a register instead of memory/stack space. In some cases, there won't be enough registers for every variable you place this keyword on so placing it on too many variables can force some of the others out of registers again.

这仅仅是一个暗示,虽然和编译器没有把它。

This is just a hint, though, and the compiler doesn't have to take it.

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

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