// 메모리 누수 탐지 하는 다른 방법
void Dump_Blocks_In_All_Heaps ()
{
//get all the heaps in the process
HANDLE heaps [100];
DWORD c = ::GetProcessHeaps (100, heaps);
printf ("The process has %d heaps.\n", c);
//get the default heap and the CRT heap (both are among
//those retrieved above)
const HANDLE default_heap = ::GetProcessHeap ();
const HANDLE crt_heap = (HANDLE) _get_heap_handle ();
for (unsigned int i = 0; i < c; i++)
{
//query the heap attributes
ULONG heap_info = 0;
SIZE_T ret_size = 0;
if (::HeapQueryInformation (heaps [i],
HeapCompatibilityInformation,
&heap_info,
sizeof (heap_info),
&ret_size))
{
//show the heap attributes
switch (heap_info)
{
case 0:
printf ("Heap %d is a regular heap.\n", (i + 1));
break;
case 1:
printf ("Heap %d is a heap with look-asides (fast heap).\n", (i + 1));
break;
case 2:
printf ("Heap %d is a LFH (low-fragmentation) heap.\n", (i + 1));
break;
default:
printf ("Heap %d is of unknown type.\n", (i + 1));
break;
}
if (heaps [i] == default_heap)
{
printf (" This the DEFAULT process heap.\n");
}
if (heaps [i] == crt_heap)
{
printf (" This the heap used by the CRT.\n");
}
//walk the heap and show each allocated block inside it
//(the attributes of each entry will differ between
//DEBUG and RELEASE builds)
PROCESS_HEAP_ENTRY entry;
memset (&entry, 0, sizeof (entry));
int count = 0;
while (::HeapWalk (heaps [i], &entry))
{
if (entry.wFlags & PROCESS_HEAP_ENTRY_BUSY)
{
printf (" Allocated entry %d: size: %d, overhead: %d.\n", ++count, entry.cbData, entry.cbOverhead);
}
}
}
}
}
'개발언어 > c++' 카테고리의 다른 글
Implementing the __FUNCTION__ Macro in VC++ 6.0 (0) | 2016.07.16 |
---|---|
Memory(-Leak) and Exception Trace (CRT and COM Leaks) (0) | 2016.07.16 |
윈도우 시스템 정보 얻기 (0) | 2016.07.16 |
MFC 다국어 지원 방법(국가별 언어설정) (0) | 2016.07.15 |
ATL Event Thread, ATL 쓰레드 이벤트 발생 시키기 (0) | 2016.07.09 |