数组大小错误x64进程 [英] Array size error x64 process

查看:129
本文介绍了数组大小错误x64进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查可以在X64应用程序上创建的数组的大小,我的理解是,我可以在X64进程上创建大于2 ^ 31的数组,但是在代码如下的VS2010编译器上出现编译错误

I was checking how big of an array can I create on a X64 application, my understanding was that I can create arrays bigger than 2^31 on X64 process but I'm getting a compilation error on VS2010 compiler, below code

const size_t ARRSIZE = size_t(1)<<32;
int main()
{
    char *cp = new char[ARRSIZE];
    return 0;
}

在目标x64平台上的VS2010上,给出编译器错误错误C2148:数组的总大小不能超过0x7fffffff字节" , );

gives compiler error "error C2148: total size of array must not exceed 0x7fffffff bytes" on VS2010 on target x64 platform, I can create upto (size_t(1)<<32 - 1);

我有Linker-> Advanced-> Target Machine是Machinex64. 另外,Linker-> System-> Enable Large Addresses as Yes(不确定是否确实如此). pc中存在的分页文件\ Physical Ram是否重要? (我确定它是一个64位应用程序,因为如果我删除该行并仅使用char * cp,则为8字节.) 我是否缺少某些设置?

I have Linker->Advanced->Target Machine is Machinex64. Also Linker->System->Enable Large Addresses as Yes ( Not sure if this really matters ). Does the paging file\Physical Ram present in the pc matter here? (I'm sure that it is a 64-bit app because if I remove that line and just have char* cp; it is 8-byte.) Am I missing some settings?

推荐答案

这似乎是x64目标的32位交叉编译器中的缺陷. icabod在上面的评论中发布的Microsoft Connect链接解决了此特定问题.不幸的是,该错误的状态已设置为已关闭-无法修复.

This appears to be a defect in the 32-bit cross compiler for x64 targets. The Microsoft Connect link posted by icabod in the comments above addresses this particular issue. Unfortunately the bug's status has been set to Closed - Won't Fix.

以下代码段将无法使用用于x64的32位交叉编译器进行编译:

The following code snippets will fail to compile using the 32-bit cross compiler for x64:

char* p = new char[(size_t)1 << 32];

const size_t sz = (size_t)1 << 32;
char* p = new char[sz];

使用x64的32位交叉编译器进行编译时,上述两种方法都将失败,并显示错误消息error C2148: total size of array must not exceed 0x7fffffff bytes.不幸的是,即使在以x64为目标的64位版本的Windows上运行,Visual Studio仍会启动32位编译器.

Both of the above will fail with the error message error C2148: total size of array must not exceed 0x7fffffff bytes when compiled with the 32-bit cross compiler for x64. Unfortunately, Visual Studio does launch the 32-bit compiler even when run on a 64-bit version of Windows, targetting x64.

可以应用以下解决方法:

The following workarounds can be applied:

  • 从命令行使用适用于x64的本机64位编译器编译代码.
  • 将代码更改为以下任意一项:

  • Compiling the code using the native 64-bit compiler for x64 from the command line.
  • Changing the code to either of the following:

size_t sz = (size_t)1 << 32;  // sz is non-const
char* p = new char[sz];

std::vector<char> v( (size_t)1 << 32 );

Visual Studio 2012中仍然存在该错误,并且所有变通办法仍然适用.

The bug is still present in Visual Studio 2012, and all workarounds still apply.

这篇关于数组大小错误x64进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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