在C#中注册 [英] Registers in C#

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

问题描述

我们都知道堆栈和堆的概念,但是我最近阅读了有关保存数据的第三个选项:寄存器.

we all know the idea of stack and heap, but I recently read about a third option to save data: registers.

我很难找到有关此类型的好文章,发现的是: http://www.dotnetperls.com/method-parameter ,以及用于C的很多内容,例如:

I have a hard time finding good articles about this type, what I found was: http://www.dotnetperls.com/method-parameter, and a lot of stuff for C, for example: http://igoro.com/archive/volatile-keyword-in-c-memory-model-explained/

到目前为止,我仅有的真实信息是:每个CPU都有自己的寄存器,这些寄存器可用于保存数据,可以以最快的方式访问数据,例如在for循环中.

The only real informations I have so far: every CPU has its own registers, which can be used to save data, which is accessed at the fastest way possible, for example in the for loops.

据我所知,这种注册是由CLR进行的.然后我想起了这个volatile关键字,如果我们看一下MSDN:

As far as I've seen, this en-registering is made by the CLR. Then I remembered this volatile-keyword, and if we look at MSDN:

volatile关键字指示字段可以通过以下方式修改同时执行的多个线程.的字段是声明为volatile不受编译器优化的限制,假设通过单个线程进行访问.这样可以确保字段中始终存在最新值.

The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time. Fields that are declared volatile are not subject to compiler optimizations that assume access by a single thread. This ensures that the most up-to-date value is present in the field at all times.

那么挥发物到底是那样吗?它告诉CLR不要使用CPU寄存器,而是使用堆栈/堆,所有CPU/线程都可以访问该堆栈/堆?

So does the Volatile exactly that? It tells the CLR not to use the CPU register but the stack/heap, which can be accesses by all CPUs/threads?

对于这个令人困惑的问题,我们深表歉意,但是关于这个话题的信息确实很少.

I'm sorry for my confusing question, but there is really little information on this topic around.

推荐答案

每个CPU都有自己的寄存器"

"Every CPU has his own Register"

每个CPU都有一组寄存器,这些寄存器用于涉及任何数据的大多数操作.通常,一条指令将一些数据从内存加载到寄存器中,然后另一条指令对寄存器中的数据进行一些计算.

Every CPU has a set of registers, that are used for most operations that involve any data. Typically an instruction loads some data from memory into a register, then another instruction does some calculations on the data in the register.

CPU有一些用于数据的寄存器,一些用于指针的寄存器,以及一些用于跟踪程序执行情况的特殊寄存器,例如指令指针,堆栈指针和标志寄存器.

The CPU has a few registers that are intended for data, some that are intended for pointers, and some special registers that keep track of program execution like the instruction pointer, the stack pointer and the flags register.

由于CPU具有多个寄存器,因此JIT编译器有时可以将其中一些用作局部变量的存储.寄存器专用于保存变量的值,而不是在堆栈上分配变量.

As the CPU has several registers, the JIT compiler can sometimes use a few of them as storage for local variables. Instead of allocating the variable on the stack, the register is dedicated to hold the value of the variable.

volatile 关键字不影响寄存器如何用于存储.如果一个变量可以被不同的线程访问,那么不是那种存储在寄存器中的变量.实际上,只有局部变量具有有限的范围和较短的寿命,才会存储在寄存器中.

The volatile keyword doesn't affect how registers can be used for storage. If a variable can be accessed by different threads, then it's not the kind of variable that is a candidate to be stored in a register. In practive, it's just local variables with a limited scope and short life span that will be stored in registers.

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

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