凡在C变量++存储? [英] Where are variables in C++ stored?

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

问题描述

如果在C ++的变量存储?

Where are variables in C++ stored?

在RAM或处理器的缓存?

Inside the RAM or the processor's cache?

推荐答案

变量存储:


    堆栈上的
  • ,如果他们汽车 -MATIC功能局部变量

  • 在堆上,如果他们与分配新的的malloc 等。(什么是细节意思是说的变量被存储在堆中的评论)

  • 在,如果他们是全球或静态
  • 每个进程的数据区
  • on the stack, if they're auto-matic function-local variables
  • on the heap, if they're allocated with new or malloc, etc. (details of what it means to say "a variable is stored in the heap" in the comments)
  • in a per-process data area if they are global or static

这是所有在RAM中,当然。缓存是透明的,用户空间的进程,虽然它可能visibily影响性能。

This is all in RAM, of course. Caching is transparent to userspace processes, though it may visibily affect performance.

编译器可以优化code在寄存器中存储的变量。这是非常编译器和code依赖,但良好的编译器会做如此积极。

Compilers may optimize code to store variables in registers. This is highly compiler and code-dependent, but good compilers will do so aggressively.

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

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