_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는 디버깅 함수 두 개를 추가합니다. 반환되는 크기에서 메모리 블록의 사용자 부분 한쪽에는 버퍼가 포함되며, 특정 블록 유형에 대해 크기를 계산할 수 있습니다.

기본 힙의 디버그 버전에서 메모리 블록을 할당, 초기화 및 관리하는 방법에 대한 자세한 내용은 CRT 디버그 힙 세부 정보를 참조 하세요. 할당 블록 형식 및 사용 방법에 대한 자세한 내용은 디버그 힙의 블록 유형을 참조 하세요. 표준 힙 함수와 디버그 버전 간의 차이점에 대한 자세한 내용은 힙 할당 함수의 디버그 버전을 참조 하세요.

이 함수는 해당 매개 변수의 유효성을 검사합니다. null 포인터인 경우 memblock 매개 변수 유효성 검사에 설명된 대로 잘못된 매개 변수 처리기를 호출합니다. _msize_dbg 오류가 처리되면 함수는 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 );
}

출력

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

참고 항목

디버그 루틴
_malloc_dbg