[C++]使用Pageheap偵測記憶體越界錯誤
pageheap Displays pageheap enabled programs
pageheap /enable PROGRAM Enables page heap for PROGRAM
pageheap /enable PROGRAM FLAGS Enables page heap for PROGRAM using
FLAGS (hex number) for heap flags.
pageheap /disable PROGRAM Disables page heap for PROGRAM
pageheap PROGRAM Displays current setting for PROGRAM
Example: pageheap /enable notepad
pageheap /disable pbrush
Note. Enabling page heap does not affect currently running
processes. If you need to use page heap for processes that are
already running and cannot be restarted (csrss.exe, winlogon.exe),
a reboot is needed after the page heap has been enabled for
that process.
FLAGS hex value (0x…) has the following structure:
B7-B0 Bit flags 1 - enable page heap
01 - enable page heap. If zero normal heap is used.
In 99% of the cases you will want this to be set.
02 - collect stack traces (default on checked builds)
04 - minimize memory impact
08 - minimize randomly(1)/based on size range(0)
10 - catch backward overruns
B15-B8 Percentage of available memory from total memory below
which allocations will be made from normal heap. Used
in conjuction with bit flag 04.
B31-B24 Probability for page heap allocation. Bit 4 and 8 must
be set.
B31-B24 Size range start
B23-B16 Size range end
Allocations in this size range will be made in page heap.
Bit 4 must be set and bit 8 must be reset.
Examples:
pageheap /enable PROGRAM 0x03
Enable stack trace collection on free builds where it is not
the default.
pageheap /enable PROGRAM 0x13
Put the not accessible page at the begining of the allocation
and enable stack traces.
pageheap /enable PROGRAM 0x3000300F
With 48% probability allocate in page heap. If memory gets
below 48% then all allocations are done in normal heap.
int _tmain(int argc, _TCHAR* argv[])
{
int m_len = 5;
char *m_p = (char *)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, m_len);
m_p[m_len] = 0;
HeapFree (GetProcessHeap (),0, m_p);
return 0;
}