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

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

问题描述

我有一个需要大型二维数组的小型 C++ 程序.

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

int distanceArray[282][9900000];

我知道标准的 32 位控制台应用程序无法为我的进程分配这么多内存,因为 32 位应用程序有 2GB 的上限.但是,尽管我已将编译器配置为使用本机 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!

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

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