_CrtSetBreakAlloc

指定されたオブジェクト割り当て順序番号にブレークポイントを設定します (デバッグ バージョンのみ)。

構文

long _CrtSetBreakAlloc(
   long lBreakAlloc
);

パラメーター

lBreakAlloc
ブレークポイントを設定する割り当て順序番号。

戻り値

ブレークポイントが設定されていた、以前のオブジェクト割り当て順序番号を返します。

解説

_CrtSetBreakAlloc を使用すると、アプリケーションはメモリ割り当ての特定の位置でブレークし、要求元をさかのぼって調べることにより、メモリ リークの検出を実行できます。 関数は、メモリ ブロックがヒープ上に割り当てられたときに決められた、シーケンシャルなオブジェクト割り当て順序番号を使用します。 _DEBUG が定義されていない場合、_CrtSetBreakAlloc の呼び出しは前処理で削除されます。

オブジェクトの割り当て順序番号は、Crtdbg.h 内で定義されている _CrtMemBlockHeader 構造体の lRequest フィールド内に格納されます。 いずれかのデバッグ ダンプ関数を使用してメモリ ブロックの情報を出力すると、この番号が {36} のように中かっこで囲まれて表示されます。

_CrtSetBreakAlloc を他のメモリ管理関数と共に使用する方法について詳しくは、「ヒープ割り当て要求を追跡する」を参照してください。 デバッグ バージョンのベース ヒープでのメモリ ブロックの割り当て、初期化、管理の方法について詳しくは、「CRT デバッグ ヒープの詳細」を参照してください。

要件

ルーチンによって返される値 必須ヘッダー
_CrtSetBreakAlloc <crtdbg.h>

互換性の詳細については、「 Compatibility」を参照してください。

ライブラリ

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

関連項目

デバッグ ルーチン