程序堆栈和堆,它们如何工作? [英] Program stack and heap, how do they work?

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

问题描述

我知道每个正在运行的进程在虚拟内存中都有与之关联的页面,并且只有少数页面会根据需要加载到主内存中.我也知道该程序将具有一个堆栈和一个堆来分配动态内存.这是我的问题.

I know that every running process has pages associated with it in virtual memory and few of them will be loaded into main memory as required. I also know that program will have a stack and also a heap to allocate dynamic memory. Here are my questions.

  1. 堆栈也是主存储器中某些页面的一部分吗?
  2. 当程序进入等待状态时会发生什么?堆栈指针,程序计数器和其他信息存储在哪里?
  3. 为什么堆栈变小而堆变大?
  4. L1,L2高速缓存只能包含一块连续的内存,还是可以有一部分堆栈和堆?

您能推荐一本涵盖这些内容的好书吗?

Can you recommend any good book that covers these things?

推荐答案

  1. 是-堆栈通常存储在内存的低"地址中,并朝其上限向上填充.堆通常存储在地址空间的顶部",并朝着堆栈的方向增长.

  1. Yes - the stack is typically stored in the "low" addresses of memory and fills upward toward its upper limit. The heap is typically stored at the "top" of the address space and grows toward the stack.

O/S在每个正在运行的进程中存储一个上下文".保存和恢复进程状态的操作称为上下文切换".

The O/S stores a "context" per running process. The operation of saving and restoring process state is called a "context switch."

只是一个约定的AFAIK.堆栈并没有真正地增长",它具有固定分配.

Just a convention AFAIK. The stack doesn't really "grow" it's got fixed allocation.

缓存仅包含已使用的RAM部分(最近或附近)的快照.在任何时候,它们都可以从其中地址空间的任何部分获得内存.显示在何处的内容在很大程度上取决于缓存的结构参数(块长度,关联性,总大小等).

Caches simply contain snapshots of parts of RAM that have been used (either recently or nearby). At any moment in time they can have memory from any part of the address space in them. What shows up where depends heavily on the structural parameters of the cache (block length, associativity, total size, etc.).

我建议计算机体系结构:一种定量方法作为基础硬件以及有关如何管理"硬件的任何书籍的参考.

I would suggest Computer Architecture: A Quantitative Approach as a good reference on the underlying hardware and any book on Operating Systems for how the hardware is "managed."

这篇关于程序堆栈和堆,它们如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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