我的服务器运行一段时间后,在new一个对象时,或者new int[5],凡是申请内存的地方有异常。
出现“Unhandled exception in Server.exe (MSVCRT.DLL):0xC0000005 Access Violation”
异常,请问会是什么原因导致的呢?(我用F5调试定位的)
出现“Unhandled exception in Server.exe (MSVCRT.DLL):0xC0000005 Access Violation”
异常,请问会是什么原因导致的呢?(我用F5调试定位的)
#include <stdio.h>void Thd(void)
{
while (1)
{
char *buf = new char[4096];
delete [] buf;
buf = 0;
Sleep(100);
printf("thrd \n");
}
}int main(void)
{
for(int i=0; i<4; i++)
CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)Thd, NULL, NULL, NULL);
while(1)
{
printf("main \n");
Sleep(5000);
}
return 1;
}
2.vc是pack几,建议打包pack5试一下
3.关注!
线程函数原型不对,造成堆栈被破坏?
LPVOID lpParameter
);
#include <stdio.h>DWORD WINAPI Thd(LPVOID)
{
while (1)
{
char *buf = new char[4096];
delete [] buf;
buf = 0;
Sleep(100);
printf("thrd \n");
}
return 0;
}int main(void)
{
for(int i=0; i<4; i++)
CreateThread(NULL,NULL,Thd, NULL, NULL, NULL);
while(1)
{
printf("main \n");
Sleep(5000);
}
return 1;
}