堆栈内存是否连续? [英] Is stack memory contiguous?

查看:185
本文介绍了堆栈内存是否连续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译器如何强制执行堆栈内存是连续的,是否会导致内存在程序运行时每次都被移动,或者是在程序运行之前保留堆栈所需的内存吗?

How does the compiler enforce the stack memory to be contiguous, does it cause the memory to be moved everytime while the program is running or does it reserve the memory on stack needed by program before running it?

推荐答案

给定线程的堆栈通常在虚拟内存中是连续的(在Linux和类似系统上,在Windows的用户模式下)。 Windows内核(在Windows Vista及更高版本中) z / OS 允许在虚拟内存中存在不连续的堆栈, GCC 4.6也将允许。编译器不需要移动堆栈,即使对于堆栈具有不连续的虚拟地址的系统;他们只是改变分配新部件的地方。操作系统可能会将物理页面重新映射到虚拟内存,以使堆栈在物理内存中不连续,即使它在虚拟内存中。

The stack for a given thread is often contiguous in virtual memory (on Linux and similar systems, and in user mode in Windows). The Windows kernel (in Windows Vista and above) and z/OS allow discontiguous stacks in virtual memory, and GCC 4.6 will also allow that. The compiler does not need to move the stack around at all, even for the systems that have discontiguous virtual addresses for the stack; they just change where new parts are allocated. The operating system might remap physical pages to virtual ones so that the stack may not be contiguous in physical memory, though, even if it is in virtual memory.

这篇关于堆栈内存是否连续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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