내가 구현한 프로그램은 핵심 모듈은 초 당 1000Hz의 샘플링 레이트로 데이터를 처리하는 부분이다.
이 프로그램을 디버그 모드로 장기 테스트를 돌리면, 꼭 이틀 정도가 지나면... 강제적으로 위 그림과 같이 _CrtDbgBreat(); 에 브레이크 포인트가 걸린다.
위 코드는 _heap_alloc_dbg()의 일부분이다.
이 문제의 근본적인 원인은 바로 if(lRequest == _crtBreakAlloc) 이 부분이다. 그리하여, 디버그 모드에서 NEW를 2^32 - 1회 호출하면, 자동으로 이 곳에 도달하게 되는 것이다.
친절한 구글사마를 통해 알아본 결과, 위와 같은 문제를 해결하는 방법에는 4가지가 있는데... 그 방법은 다음과 같다. (원문을 그대로 붙인다.)
more..
Mick Mathers wrote: > I built a "debug" build of my application because I was > having an intermittant problem. I set a breakpoint and > went away. When I return, a hard-coded breakpoint had been > hit. I tracked this down to heap_alloc_dbg().
> Has anyone else found this problem?
This is a known bug...
There are four possible solutions:
1. Recompile the C-Runtime by yourself and change the code to: (but then you have to use own names instead of MSVCRT!)
/* break into debugger at specific memory allocation */ if (_crtBreakAlloc != -1L && lRequest == _crtBreakAlloc) _CrtDbgBreak();
2. Update to VC7
3. Register your own hook for allocation, and set the _crtBreakAlloc to a valid value...:
int __cdecl MyAllocHook( int nAllocType, void * pvData, size_t nSize, int nBlockUse, long lRequest, const unsigned char * szFileName, int nLine ) { switch(nAllocType) { case _HOOK_ALLOC: case _HOOK_REALLOC: _crtBreakAlloc = lRequest-1; break; } return 1;
}
void main() { _CrtSetAllocHook(MyAllocHook);
char *pTest = NULL; // do arround 0x10 * 0x100000000 allocs (the lRequest-value wraps 0x10 times....) for (int a = 0; a < 10; a++) { for(int b = 0; b <= 0xffffffff; b++) { pTest = (char*) malloc(10); strcpy(pTest, "sodelle"); free(pTest); } printf("\nWrap %d", b+1); }
}
4. Do not use the debug heap...
-- Greetings Jochen
결국 가장 간단한 방법은 VC를 7.0 이상으로 쓰는 것인데... 이상하게도 C++은 아직도 6.0이 가장 편한 것 같다. 왠지 7.0 이상은 화면부터 맘에 안 들어--; (그럼에도 불구하고, C# 할 때는 VS 2005를 잘 쓰고 있다.)
Comments