可能重复:
Stack overflow visual C++, potentially array size?的Visual C++数组大小崩溃
此代码被简单地指为从二进制文件到阵列的DataBuffer读取值。当DataBuffer的大小大于或等于515000时,它就会崩溃。我在Windows 7上的Visual C++ 2010中开发了这个功能。函数cbFileRead()是我无法访问的源代码。 cbFileRead()期望DataBuffer的类型为USHORT *。
#include <stdio.h> // printf()
#include "cbw.h" // cbFileRead()
int main(int argc, char* argv[]) {
// Declarations
char* FileName = argv[1];
long FirstPoint = 0;
long NumPoints;
// Set data collection sizes
const long chunkSize = 515000;
NumPoints = chunkSize; // Number of points to be read into mem
WORD DataBuffer[chunkSize-1];
// Get data
cbFileRead(FileName, FirstPoint, &NumPoints, DataBuffer);
printf("Completed on data point %d whose value is %d\n", NumPoints, DataBuffer[chunkSize-1]);
return 0;
}
这个崩溃有什么原因?我希望阵列大小能够变得更高。
默认情况下,您通常会有一个非常小的堆栈。我会使用'std :: vector'而不是 – Flexo 2012-07-11 14:10:40
这看起来像C,而不是C++?为什么它被标记为C++? – 2012-07-11 14:11:03
Windows中的堆栈大约为1MB(或2),IIRC。 – nhahtdh 2012-07-11 14:11:32