进程用户态虚拟地址空间上限测试

本文探讨了Linux和Windows系统中,32位环境下进程用户态虚拟地址空间的上限。在Linux上,默认情况下,对于x86 CPU有3G/1G和1G/3G两种分配方式;而在Windows上,默认为2GiB,通过设置可扩展到3GiB,但会减少内核模式的地址空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2013-05-04 wcdj

向青年节致敬!


问题:堆空间最大可以申请多少呢?

测试: 

#include <iostream>
#include <cstdlib>   
#include <new>        

void no_memory () {
	std::cout << "Failed to allocate memory!\n";
	std::exit (1);
}

unsigned long size = 2*1024*1024*1024ul + 1024*1024*700;

int main () {
	std::set_new_handler(no_memory);
	std::cout << "attempting to allocate " << size << "... ";
	char* p = new char [size];
	memset(p, 0x01, size);
	std::cout << "ok\n";
	sleep(20);
	delete[] p;
	return 0;
}


结论:

(1) 对于Linux

For x86 CPUs, Linux allows split the user and kernel address ranges in differents ways: 3G/1G user/kernel (default) , 1G/3G user/kernel or 2G/2G user/kernel.

(2) 对于Windows

On a 32-bit Microsoft Windows installation, by default, only 2 GiB are made available to processes for their own use. The other 2GB are used by the operating system. On later 32-bit editions of Microsoft Windows it is possible to extend the user-mode virtual address space to 3 GiB while only 1 GiB is left for kernel-mode virtual address space by marking the programs as IMAGE_FILE_LARGE_ADDRESS_AWARE and enabling the /3GB switch in the boot.ini file.


https://en.wikipedia.org/wiki/Virtual_address_space

https://msdn.microsoft.com/en-us/library/aa366912(VS.85).aspx


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值