_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**新增兩個偵錯功能: 其中包括使用者部份的記憶體區塊的任一邊的緩衝區中傳回的大小,並可讓特定的區塊類型的大小計算。

如需有關如何記憶體區塊會配置、 初始化,而且在基底堆積的偵錯版本管理的資訊,請參閱記憶體管理和偵錯堆積。配置的區塊型別和它們的使用方式的相關資訊,請參閱類型的區塊在偵錯堆積上。呼叫 [應用程式的偵錯組建中的 [標準的堆積函式和它的偵錯版本之間的差異的相關資訊,請參閱使用偵錯版本 Versus 基底版本

這個函式會驗證它的參數。如果memblock是空值的指標, _msize中所述,將不正確的參數處理常式中,會叫用參數驗證。如果錯誤處理時,此函式會將errnoEINVAL ,並傳回-1。

需求

常式

所需的標頭

_msize_dbg

<crtdbg.h>

如需相容性資訊,請參閱相容性在簡介中。

文件庫

偵錯版本的 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 );
}

Output

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