本文介绍了有限的分配大小C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2008.
我已动态声明变量big_massive:

I use Visual Studio 2008.I have dynamically declared the variable big_massive:

unsigned int *big_massive = new unsigned int[1073741824]

但是,当我试图调试这个程序时, 无效的分配大小:4294967295字节。
我希望有任何路径,以避免此类错误?谢谢!

But, when I tried to debug this program, I got following error: Invalid allocation size: 4294967295 bytes.I hope there are any path to avoid such error? Thank you!

推荐答案

这种分配根本不可能在32位x86系统上使用 sizeof(int)= = 4 (您正在请求4GB)。进程的总地址空间限制为4GB,并且进程本身通常限制为小于2GB或3GB(对于32位Windows,取决于 boot.ini 设置和Windows版本,不确定哪个限制适用于64位Windows上的32位进程,但4GB根本不可能)。

That allocation is simply not possible on 32bit x86 systems with sizeof(int)==4 (you are requesting 4GB). A process's total address space is limited to 4GB, and the process itself is usually limited to less than that (2GB or 3GB for 32bit Windows depending on boot.ini settings and the Windows edition, not sure which limit applies for 32bit processes on 64bit Windows, but 4GB is simply not possible).

对于64位的情况,您需要有4GB虚拟内存可用于备份该分配以使其成功。

For the 64bit case, you'd need to have 4GB of virtual memory available to back that allocation for it to succeed.

这篇关于有限的分配大小C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 01:19