此代码导致与 Visual Studio 2010 对应的堆损坏。是什么导致堆损坏?这段代码的哪一部分导致了它?
#define size 65536
int main()
{
int* a = new int[size];//size is equal to
srand(time(NULL));
for(int i = 0 ; i < size; i++)
{
a[i]= 1 + rand() % 10;
}
for(int i = 0; (size / 2) / pow((double)2, i)>= 1; i++)
{
int n = pow((double)2, i);
int offset = 0;
for(int j = 0; j < (size / 2) / pow((double)2, i); j++)
{
int* tmp = new int[n];
merge(a + offset, n, a + offset + n, n, tmp);
memcpy(a + offset, tmp, n*2 * sizeof(int));
offset += pow((double)2, i+1);
}
}
for(int i = 0; i < size; i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
system("PAUSE");
return 0;
}