_msize_dbg

ヒープ内のメモリ ブロックのサイズを計算します (デバッグ バージョンのみ)。

構文

size_t _msize_dbg(
   void *userData,
   int blockType
);

パラメーター

userData
サイズを調べるメモリ ブロックへのポインター。

blockType
指定したメモリ ブロックの種類: _CLIENT_BLOCK または _NORMAL_BLOCK.

戻り値

正常に完了すると、 _msize_dbg 指定されたメモリ ブロックのサイズ (バイト単位) が返されます。それ以外の NULL場合は 、

解説

_msize_dbg は_msize 関数のデバッグ バージョンです。 定義されていない場合 _DEBUG 、各呼び出しは次の呼び _msize_dbg 出し _msizeに減らされます。 _msize_msize_dbg は、どちらもベース ヒープ内のメモリ ブロックのサイズを計算しますが、_msize_dbg は 2 つのデバッグ機能を追加します。返されるサイズにメモリ ブロックのユーザー部分の両側のバッファーを含める機能と、特定のブロック型のサイズ計算ができるようにする機能です。

基本ヒープのデバッグ バージョンでのメモリ ブロックの割り当て、初期化、および管理方法については、CRT デバッグ ヒープの詳細を参照してください。 割り当てブロックの種類とその使用方法については、「デバッグ ヒープ上のブロックの種類」を参照してください。 標準ヒープ関数とデバッグ バージョンの違いについては、ヒープ割り当て関数のデバッグ バージョンを参照してください

この関数は、そのパラメーターを検証します。 null ポインターの場合memblockは、「_msize_dbgパラメーターの検証」で説明されているように、無効なパラメーター ハンドラーを呼び出します。 エラーが処理されると、errnoEINVAL に設定され、-1 が返されます。

必要条件

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

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

ライブラリ

C ランタイム ライブラリのデバッグ バージョンのみ。

// crt_msize_dbg.c
// compile with: /MTd
/*
* This program allocates a block of memory using _malloc_dbg
* and then calls _msize_dbg to display the size of that block.
* Next, it uses _realloc_dbg to expand the amount of
* memory used by the buffer and then calls _msize_dbg again to
* display the new amount of memory allocated to the buffer.
*/

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <crtdbg.h>

int main( void )
{
        long *buffer, *newbuffer;
        size_t size;

        /*
         * Call _malloc_dbg to include the filename and line number
         * of our allocation request in the header
         */
        buffer = (long *)_malloc_dbg( 40 * sizeof(long), _NORMAL_BLOCK, __FILE__, __LINE__ );
        if( buffer == NULL )
               exit( 1 );

        /*
         * Get the size of the buffer by calling _msize_dbg
         */
        size = _msize_dbg( buffer, _NORMAL_BLOCK );
        printf( "Size of block after _malloc_dbg of 40 longs: %u\n", size );

        /*
         * Reallocate the buffer using _realloc_dbg and show the new size
         */
        newbuffer = _realloc_dbg( buffer, size + (40 * sizeof(long)), _NORMAL_BLOCK, __FILE__, __LINE__ );
        if( newbuffer == NULL )
               exit( 1 );
        buffer = newbuffer;
        size = _msize_dbg( buffer, _NORMAL_BLOCK );
        printf( "Size of block after _realloc_dbg of 40 more longs: %u\n", size );

        free( buffer );
        exit( 0 );
}

出力

Size of block after _malloc_dbg of 40 longs: 160
Size of block after _realloc_dbg of 40 more longs: 320

関連項目

デバッグ ルーチン
_malloc_dbg