关于记忆模型 [英] about memory model

查看:78
本文介绍了关于记忆模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想知道哪里&如何存储C变量

i意味着像volatile,指针和字符串变量一样存储,

无论是在堆栈还是其他地方

如果有任何明确的文件,PLZ建议链接

hi
i want to know where & how the C variables gets stored
i mean like volatile , pointer and string variables gets stored ,
whether it is on stack or some other places
if is there any clear document , plz suggest the link

推荐答案

kumar写道:
kumar wrote:

hi

i想知道哪里&如何存储C变量

i意味着像volatile,指针和字符串变量一样存储,

无论是在堆栈还是其他地方

如果有任何明确的文件,plz建议链接
hi
i want to know where & how the C variables gets stored
i mean like volatile , pointer and string variables gets stored ,
whether it is on stack or some other places
if is there any clear document , plz suggest the link



单词是please。


最好的地方找到答案在您的编译器或平台上

文档。存储变量的详细信息是

具体实现。


-

Ian Collins。

The word is "please".

The best place to find the answer is in your compiler or platform
documentation. The details of where variables are stored are
implementation specific.

--
Ian Collins.


2008年5月26日星期一上午12:29:21 -0700,kumar写道:
On Mon, May 26, 2008 at 12:29:21AM -0700, kumar wrote:

hi

i想知道哪里&如何存储C变量

i意味着像volatile,指针和字符串变量一样存储,

无论是在堆栈还是其他地方
hi
i want to know where & how the C variables gets stored
i mean like volatile , pointer and string variables gets stored ,
whether it is on stack or some other places



C的好处在于,当你用标准C编程时,你不必考虑这个

。每当你想到这些细节时

你失去了程序的可移植性,因为

变量的存储留给了实现者自行决定。


栈的概念是不是语言的一部分,但是具有

自动存储的变量(没有静态关键字的局部变量)是大多数系统在某种堆栈上存储的.b $ b。全局变量

和使用static关键字声明的变量存储在指定的内存中,并且在调用main()之前初始化它们。

每次调用malloc()时,都会从操作系统询问动态变量的内存,

。还有一个其他存储类说明符,

寄存器,这表明变量应存储在cpu寄存器中,

但是编译器可以自由地忽略该关键字(但是所有必须记录

注册关键字的效果。)

限定符(例如const,volatile)不影响存储,但它们是

确实会对这些变量的访问产生影响。


如果不了解你的系统和你的意图,很难说清楚。

这不礼貌询问你是否真的需要你所要求的信息,

但很难抗拒。


Szabolcs

The nice thing with C is that you do not have to think about this
when you program in standard C. Whenever you think about these details
you loose the portability of your program, since the storage of the
variables is left for the discretion of the implementors.

The concept of stack is not part of the language, but variables with
automatic storage (local variables without the static keyword) are
stored by most systems on some sort of stack. The global variables
and those declared with the static keyword are stored in a designated
section of memory, and they are initialised before main() is called.
The memory for dynamical variables are asked from the operating system,
whenever you call malloc(). There is an other storage class specifier,
register, which suggests that the variable should be stored in a cpu register,
but compilers are free to ignore that keyword (but all have to document
the effect of the register keyword.)
The qualifiers (e.g. const, volatile) do not affect the storage, but they
do have an impact on the access to those variables.

It is difficult to tell more without knowing your system and your intentions.
It is not polite to ask if you really need the information you have asked for,
but it is difficult to resist.

Szabolcs


Szabolcs Borsanyi写道,On 26/05/08 10:18:
Szabolcs Borsanyi wrote, On 26/05/08 10:18:

2008年5月26日星期一12点: 29:21 AM -0700,kumar写道:
On Mon, May 26, 2008 at 12:29:21AM -0700, kumar wrote:

> hi
我想知道哪里&如何存储C变量
我的意思是像volatile,指针和字符串变量一样存储,
是否在堆栈或其他地方
>hi
i want to know where & how the C variables gets stored
i mean like volatile , pointer and string variables gets stored ,
whether it is on stack or some other places



C的优点在于,当你用标准C编程时,你不必考虑这个

。每当你想到这些细节时,你就会失去你的可移植性您的程序,因为

变量的存储留给实现者自行决定。


堆栈的概念不是语言的一部分,但是变量与

自动存储(没有static关键字的局部变量)是大多数系统在某种堆栈上存储的
。全局变量


The nice thing with C is that you do not have to think about this
when you program in standard C. Whenever you think about these details
you loose the portability of your program, since the storage of the
variables is left for the discretion of the implementors.

The concept of stack is not part of the language, but variables with
automatic storage (local variables without the static keyword) are
stored by most systems on some sort of stack. The global variables



在很多系统中,至少有一些系统存储在寄存器中,如果编译器可以避免,则永远不会写入
它。


< snip>

On a lot of systems at least some of them are stored in registers and
never written to if the compiler can avoid it.

<snip>


限定符(例如const,volatile)不影响存储,但是

对访问这些变量有影响。
The qualifiers (e.g. const, volatile) do not affect the storage, but they
do have an impact on the access to those variables.



不正确。在许多系统上,const将导致变量。在某种形式的只读存储器中存储

,无论是实际的ROM还是只有在加载程序时才会将其标记为只读的页面。 />

Incorrect. On a lot of systems const will cause "variables" to be stored
in some form of read-only memory, either actual ROM or a page that the
OS will mark as read only when it loads the program.


如果不了解你的系统和你的意图,很难说出更多信息。

如果你真的需要你的信息是不礼貌的要求,

,但很难抗拒。
It is difficult to tell more without knowing your system and your intentions.
It is not polite to ask if you really need the information you have asked for,
but it is difficult to resist.



关于实现存储的方式/位置具体细节的任何问题

变量属于专用于该实现的组而不是

这里。

-

Flash Gordon

Any questions about the specifics of how/where an implementation stores
variables belong on a group dedicated to that implementation rather than
here.
--
Flash Gordon


这篇关于关于记忆模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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