_CrtSetBreakAlloc

在指定的物件配置順序編號設定中斷點 (僅限偵錯版本)。

語法

long _CrtSetBreakAlloc(
   long lBreakAlloc
);

參數

lBreakAlloc
要設定中斷點的配置順序編號。

傳回值

傳回有設定中斷點的上一個物件配置順序編號。

備註

_CrtSetBreakAlloc 允許應用程式透過在記憶體配置的特定點中斷,並追溯回要求的來源,以執行記憶體遺漏偵測。 此函式會在記憶體區塊配置於堆積中時,使用指派給記憶體區塊的循序物件配置順序編號。 若未定義 _DEBUG,將會在前置處理期間移除對 _CrtSetBreakAlloc 的呼叫。

物件配置順序編號會儲存在定義於 Crtdbg.h 中的 _CrtMemBlockHeader 結構的 lRequest 欄位內。 當記憶體區塊的相關資訊由其中一個偵錯傾印函式回報時,此編號會包含在大括號裡,例如 {36}。

如需如何搭配其他記憶體管理函式使用 _CrtSetBreakAlloc 的詳細資訊,請參閱追蹤堆積配置要求 (部分機器翻譯)。 如需在偵錯版之基底堆積中如何配置、初始化及管理記憶體區塊的詳細資訊,請參閱 CRT 偵錯堆積詳細資料 (部分機器翻譯)。

需求

常式 必要的標頭
_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);

        /*
         * 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);
}

另請參閱

偵錯常式