错误:数组的总大小不能超过0x7fffffff个字节 [英] Error: Total size of array must not exceed 0x7fffffff bytes

查看:1135
本文介绍了错误:数组的总大小不能超过0x7fffffff个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的C ++程序,需要一个大型2d数组.

I have a small C++ program that requires a large 2d array.

int distanceArray[282][9900000];

我知道,由于32位应用程序的上限为2GB,因此标准的32位控制台应用程序将无法为我的进程分配这么多的内存.但是,尽管事实上我已经将编译器配置为使用本机的amd64工具集,但是在尝试构建应用程序时仍然会遇到相同的错误:

I am aware that a standard 32 bit console application would be unable to allocate this much memory to my process due to the 2GB cap on 32 bit applications. However, despite the fact that I have configured my compiler to use the native amd64 toolset, I still get the same error when I try to build my application:

Error   C2148   total size of array must not exceed 0x7fffffff bytes

我的系统上有16GB的RAM,因此我知道我的物理内存应该不是问题.如果我的计算正确,则此空间仅会占用大约3GB.但是,我不明白为什么我似乎无法使64位编译器正常工作.我已按照 Microsoft网站上的说明进行了概述. 64位编译器,但是无论我做什么,我都会收到相同的错误.任何帮助将不胜感激.谢谢!

I have 16GB of RAM on my system, so I know that my physical memory should not be an issue. If my calculations are correct, this should only take up around 3GB. However, I don't understand why I can't seem to get the 64 bit compiler to work correctly. I have followed the directions on Microsoft's website that outline how to use the 64 bit compiler, but no matter what I do, i receive the same error. Any help would be greatly appreciated. Thank you!

我知道之前曾有人问过这个问题,但是现有的答案对我没有帮助.感谢您为帮助我发现问题所做的任何尝试.

I am aware that this question has been asked before, but the existing answers have not been helpful to me. Thank you for any attempt at helping me find my problem.

推荐答案

如MSalters所建议的,std::vector<std::vector<int>>绝对是解决之道.

As suggested by MSalters, an std::vector<std::vector<int>> was definitely the way to go.

对于仍然存在此问题的任何人,这是我如何初始化它:

For anyone who is still having this problem, here is how I initialized it:

std::vector<std::vector<int>> distanceArray(282, std::vector<int>(9000000, -1));

在282个项目的每一行中创建了9,000,000列,并且每个值在开始时都初始化为-1.

9,000,000 columns are created within every row of 282 items, and each value is initialized to -1 at the start.

感谢所有评论帮助的人!

Thanks to everyone who commented for the help!

这篇关于错误:数组的总大小不能超过0x7fffffff个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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