次の方法で共有


_CrtSetBreakAlloc

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

long _CrtSetBreakAlloc( 
   long lBreakAlloc 
);

パラメーター

  • lBreakAlloc
    ブレークポイントを設定するように順序番号。

戻り値

ブレークポイントの設定をインストールする前のオブジェクトの割り当ての順序番号を返します。

解説

_CrtSetBreakAllocメモリ割り当ての特定の時点であり要求元に由来によってメモリ リークの検出を実行するアプリケーションができます。関数はヒープ上に割り当てられたときにメモリ ブロックの割り当てオブジェクトの割り当ての順序番号を使用します。_DEBUG が未定義の場合、_CrtSetBreakAlloc の呼び出しはプリプロセスで削除されます。

オブジェクトの割り当ての順序番号はCrtdbg.h で定義されている _CrtMemBlockHeader の構造体の lRequest フィールドに格納されます。メモリ ブロックの情報をダンプのデバッグ関数の 1 種類によって報告されるとこの数値は中かっこでなどの {36} で囲まれています。

詳細については**_CrtSetBreakAlloc** が別のメモリ管理関数とどのように連携できるか 追跡ヒープの割り当て要求 を参照してください。

必要条件

ルーチン

必須ヘッダー

_CrtSetBreakAlloc

<crtdbg.h>

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

ライブラリ

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 を使用します。詳細については、「プラットフォーム呼び出しの例」を参照してください。

参照

関連項目

デバッグ ルーチン