静态变量 [英] Static Variables

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

问题描述

函数内部的静态变量存储在哪里?

它在内存中的位置?就像Global进入RAM,局部变量继续

Stack ...但静态变量如何在内存中发生?

解决方案

ak*********@gmail.com 写道:


函数内部的静态变量存储在哪里?

它在内存中的位置?比如Global进入RAM,局部变量继续

Stack ...但是静态变量是如何在内存中发生的?



它这是一个实施问题。如果详细信息对您的

应用程序很重要,请参阅编译器的文档。


-

Ian Collins。


ak ********* @ gmail .com 说:


函数内部的静态变量存储在哪里?



在随机存取存储器或RAM中。 (或者,如果它是常量,可能会将

放入只读存储器或ROM中)。


它在内存中的位置?



这取决于实施。它有所不同。


就像Global进入RAM,



假设你的意思是带有外部链接的文件范围对象,是的,他们是存储在RAM中的
(除非他们是const,在这种情况下他们可能会进入
ROM)。


局部变量继续堆栈...



假设你的意思是自动对象,它们被存储在RAM中,除非

他们是const,在这种情况下他们可能会进入ROM。它们可能是某种堆栈结构中的
,或者它们可能没有。

这取决于实现。


但是静态变量是如何在内存中发生的?



它进入RAM(或者,如果它是const,它可能会进入ROM)。精确的

细节取决于实施。


-

Richard Heathfield

" Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。


编译器手册未提及有关存储的任何内容。 />

您认为什么是静态变量的最佳解决方案

存储?

Ian Collins写道:
< blockquote class =post_quotes> ak*********@gmail.com 写道:


函数内部的静态变量存储在哪里?

它在内存中的位置?就像Global进入RAM一样,局部变量继续下去

Stack ...但是静态变量如何在内存中发生?



这是一个实施问题。如果详细信息对您的

应用程序很重要,请参阅编译器的文档。


-

Ian Collins。


where does a static variable inside a function get stored?? where does
it go in memory?? like Global goes in RAM, Local variable goes on
Stack... but how does static variable takes place in memory??

解决方案

ak*********@gmail.com wrote:

where does a static variable inside a function get stored?? where does
it go in memory?? like Global goes in RAM, Local variable goes on
Stack... but how does static variable takes place in memory??

It''s an implementation issue. If the detail is important for your
application, consult your compiler''s documentation.

--
Ian Collins.


ak*********@gmail.com said:

where does a static variable inside a function get stored??

In random access memory, or "RAM" (or, if it''s const, it might get put
into read-only memory, or "ROM").

where does it go in memory??

That''s up to the implementation. It varies.

like Global goes in RAM,

Assuming you mean file scope objects with external linkage, yes, they''re
stored in RAM (unless they''re const, in which case they might go into
ROM).

Local variable goes on Stack...

Assuming you mean automatic objects, they''re stored in RAM, unless
they''re const, in which case they might go into ROM. They might be
incorporated into some kind of a stack structure, or they might not.
It''s up to the implementation.

but how does static variable takes place in memory??

It goes into RAM (or, if it''s const, it might go into ROM). The precise
details depend on the implementation.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


Compiler manual is not mentioning anything about the storage.

What do u think can be the best possible solution for static variable
storage?
Ian Collins wrote:

ak*********@gmail.com wrote:

where does a static variable inside a function get stored?? where does
it go in memory?? like Global goes in RAM, Local variable goes on
Stack... but how does static variable takes place in memory??

It''s an implementation issue. If the detail is important for your
application, consult your compiler''s documentation.

--
Ian Collins.


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

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