C ++中的RAM,硬盘,堆栈和堆如何处理? [英] What goes to RAM, Harddrive, Stack and Heap in C++?

查看:138
本文介绍了C ++中的RAM,硬盘,堆栈和堆如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这些实例,有人可以总体上说出C ++在运行时会发生什么变化(硬盘,RAM,堆栈或堆):

Could someone tell in general what goes to what (Harddrive,RAM, Stack or Heap) at runtime in C++ for these instances :

  • 局部/全局变量

  • Local/global variables

类,方法和函数

指针

对象

堆栈/堆都位于物理RAM中吗?

And is Stack/Heap both located in physical RAM?

如果有人可以在答案中加入硬件类比,我将不胜感激. 谢谢.

I would appreciate if someone could include hardware analogy in the answer. Thanks.

推荐答案

这通常取决于操作系统,但是通常是这样的:

This is generally dependent on OS, but it's generally like so:

所有内容都移至RAM.二进制文件驻留在硬盘驱动器中,但是在运行时,它与相关库一起已完全加载到RAM中.

Everything goes to RAM. The binary resides in the hard-drive, but, when ran, is fully loaded, along with dependent libraries, into RAM.

堆栈和堆是实现细节,但它们也驻留在RAM中.

Stack and heap are implementation details, but they also reside in the RAM.

尽管已加载到RAM中,但不能直接寻址该存储器.操作系统为每个进程分配虚拟内存.这意味着地址0x001实际上不在RAM中的0x001处,而是代表虚拟地址空间中的地址.

Although loaded in RAM, the memory is not directly addressable. The operating system allocates virtual memory for each process. This means that the address 0x001 is not actually located at 0x001 in the RAM, but represents an address in virtual address space.

澄清op的评论之一:

运行时二进制文件是否已全部或部分加载?而且,这些二进制文件是在运行时仅访问一次还是从硬盘连续读取?

Are binaries fully or partially loaded at runtime? And, are those binaries only accessed once at runtime or continuisly being read from Harddrive?

例如,在MS中,如果您链​​接到库,则它将在程序运行时的运行时完全加载.如果您通过LoadLibrary()以编程方式加载它,则它会在函数调用时加载到内存中,并且可以从内存中卸载.

For example, in MS, if you link against a library, it will be fully loaded at runtime, at the start of the program. If you load it programatically, via LoadLibrary(), it is loaded into memory at the function call, and can be unloaded from memory.

这篇关于C ++中的RAM,硬盘,堆栈和堆如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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