We recommend using Visual Studio 2017



The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at _aligned_msize_dbg.

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

size_t _aligned_msize_dbg(  
   void *memblock,  
   size_t alignment,  
   size_t offset  


[in] memblock
Pointer to the memory block.

[in] alignment
The alignment value, which must be an integer power of 2.

[in] offset
The offset into the memory allocation to force the alignment.

Returns the size (in bytes) as an unsigned integer.

The alignment and offset values must be the same as the values passed to the function that allocated the block.

_aligned_msize_dbg is a debug version of the _aligned_msize function. When _DEBUG is not defined, each call to _aligned_msize_dbg is reduced to a call to _aligned_msize. Both _aligned_msize and _aligned_msize_dbg calculate the size of a memory block in the base heap, but _aligned_msize_dbg adds a debugging feature: It includes the buffers on either side of the user portion of the memory block in the returned size.

This function validates its parameter. If memblock is a null pointer or alignment is not a power of 2, _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.

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.

RoutineRequired header

For more compatibility information, see Compatibility in the Introduction.

Debug versions of C run-time libraries only.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Memory Allocation