我正在创建一个动态二维数组并对其进行分配。我的 for 循环在分配错误的情况下运行 10-15 次(每次都不相同的值)后出现错误。任何帮助将不胜感激。
__int32 aLarge = 8121432;
__int32 bLarge = 8121784;
ActualPosition** myPositions;
myPositions = new ActualPosition*[aLarge];
for (int x = 0; x < aLarge; x++)
{
try
{
myPositions[x] = new ActualPosition[bLarge];
}
catch (bad_alloc& ba)
{
// Error here
}
}
最佳答案
如果 sizeof(ActualPosition) == 1
那么您将需要 61,431 GB 的内存来保存您的数组。所以除非你有一台非常大的计算机,否则你将耗尽内存。
关于c++ - 动态二维数组分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30805030/