_CrtSetBreakAlloc
在指定的物件配置順序編號 (偵錯版本) 上設定中斷點。
long _CrtSetBreakAlloc(
long lBreakAlloc
);
參數
- lBreakAlloc
配置順序編號,要設定中斷點。
傳回值
傳回已設定的中斷點上一個物件配置順序編號。
備註
_CrtSetBreakAlloc允許應用程式的記憶體配置的某一點中斷和追蹤上一步,以要求的原點,以執行記憶體遺漏偵測。函式會使用其配置在堆積中時,指定記憶體區塊的循序物件配置順序編號。當 _DEBUG 尚未定義,會呼叫**_CrtSetBreakAlloc**在前置處理過程中移除。
物件配置的順序編號會儲存在 lRequest 欄位的 _CrtMemBlockHeader Crtdbg.h 中所定義的結構。當記憶體區塊的相關資訊由其中一個偵錯傾印函式報告時,這個編號會包含在大括弧內,例如 {36}。
如需有關如何**_CrtSetBreakAlloc**可以搭配其他記憶體管理功能,請參閱追蹤堆積配置要求。
需求
常式 |
所需的標頭 |
---|---|
_CrtSetBreakAlloc |
<crtdbg.h> |
如需相容性資訊,請參閱相容性在簡介中。
文件庫
偵錯版本的 C 執行階段程式庫只。
範例
// crt_setbrkal.c
// compile with: -D_DEBUG /MTd -Od -Zi -W3 /c /link -verbose:lib -debug
/*
* In this program, a call is made to the _CrtSetBreakAlloc routine
* to verify that the debugger halts program execution when it reaches
* a specified allocation number.
*/
#include <malloc.h>
#include <crtdbg.h>
int main( )
{
long allocReqNum;
char *my_pointer;
/*
* Allocate "my_pointer" for the first
* time and ensure that it gets allocated correctly
*/
my_pointer = malloc(10);
_CrtIsMemoryBlock(my_pointer, 10, &allocReqNum, NULL, NULL);
/*
* Set a breakpoint on the allocation request
* number for "my_pointer"
*/
_CrtSetBreakAlloc(allocReqNum+2);
_crtBreakAlloc = allocReqNum+2;
/*
* Alternate freeing and reallocating "my_pointer"
* to verify that the debugger halts program execution
* when it reaches the allocation request
*/
free(my_pointer);
my_pointer = malloc(10);
free(my_pointer);
my_pointer = malloc(10);
free(my_pointer);
}
.NET Framework 對等用法
不適用。 若要呼叫標準的 c 函式,使用PInvoke。 如需詳細資訊,請參閱平台叫用範例。