Skip to content

Latest commit

 

History

History
157 lines (133 loc) · 5.09 KB

File metadata and controls

157 lines (133 loc) · 5.09 KB
title _msize_dbg | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-standard-libraries
ms.tgt_pltfrm
ms.topic article
apiname
_msize_dbg
apilocation
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
apitype DLLExport
f1_keywords
_msize_dbg
msize_dbg
dev_langs
C++
helpviewer_keywords
memory blocks
_msize_dbg function
msize_dbg function
ms.assetid a333f4b6-f8a2-4e61-bb69-cb34063b8cef
caps.latest.revision 15
author corob-msft
ms.author corob
manager ghogen
translation.priority.ht
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
ru-ru
zh-cn
zh-tw
translation.priority.mt
cs-cz
pl-pl
pt-br
tr-tr

_msize_dbg

Calculates the size of a block of memory in the heap (debug version only).

Syntax

  
      size_t _msize_dbg(  
   void *userData,  
   int blockType   
);  

Parameters

userData
Pointer to the memory block for which to determine the size.

blockType
Type of the specified memory block: _CLIENT_BLOCK or _NORMAL_BLOCK.

Return Value

On successful completion, _msize_dbg returns the size (in bytes) of the specified memory block; otherwise it returns NULL.

Remarks

_msize_dbg is a debug version of the _msize function. When _DEBUG is not defined, each call to _msize_dbg is reduced to a call to _msize. Both _msize and _msize_dbg calculate the size of a memory block in the base heap, but _msize_dbg adds two debugging features: It includes the buffers on either side of the user portion of the memory block in the returned size and it allows size calculations for specific block types.

For information about how memory blocks are allocated, initialized, and managed in the debug version of the base heap, see CRT Debug Heap Details. For information about the allocation block types and how they are used, see Types of blocks on the debug heap. For information about the differences between calling a standard heap function and its debug version in a debug build of an application, see Debug Versions of Heap Allocation Functions.

This function validates its parameter. If memblock is a null pointer, _msize invokes an invalid parameter handler, as described in Parameter Validation. If the error is handled, the function sets errno to EINVAL and returns -1.

Requirements

Routine Required header
_msize_dbg <crtdbg.h>

For more compatibility information, see Compatibility in the Introduction.

Libraries

Debug versions of C run-time libraries only.

Example

// 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  

See Also

Debug Routines
_malloc_dbg