次の方法で共有

Facebook x.com LinkedIn 電子メール

_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 つのデバッグ機能を追加します。返されるサイズにはメモリ ブロックのユーザー領域のいずれかの側のバッファーが含まれています、特定のブロックの型のサイズ計算できます。

デバッグ バージョンのベース ヒープに対するメモリ ブロックの割り当て、初期化、管理方法の詳細については、「メモリ管理とデバッグ ヒープ」を参照してください。 割り当てブロック型とその使用方法については、「デバッグ ヒープ上のメモリ ブロックの型」を参照してください。 標準で呼び出すヒープ関数と、アプリケーションのデバッグ ビルドで呼び出すデバッグ バージョンのヒープ関数との違いの詳細については、「デバッグ バージョンのヒープ割り当て関数」を参照してください。

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

必要条件

ルーチン

必須ヘッダー

_msize_dbg

<crtdbg.h>

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

ライブラリ

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

同等の .NET Framework 関数

該当なし標準 C 関数を呼び出すには、PInvoke を使用します。詳細については、「プラットフォーム呼び出しの例」を参照してください。

参照

参照

デバッグ ルーチン

_malloc_dbg


  • Last updated on 2011年08月09日