获取指针指向的内存大小方法

获取指针指向的内存大小方法

其实很简单,就是一个库函数

_msize

该函数返回在堆上分配的内存块大小,以字节为单位。因此将指针传递给这个函数就可以获取指针指向的内存大小了,不过该指针必须是动态分配的指针才行。

msdn的资料

size_t _msize( void *memblock );

Routine Required Header Compatibility
_msize <malloc.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_msize returns the size (in bytes) as an unsigned integer.

Parameter

memblock

Pointer to memory block

Remarks

The _msize function returns the size, in bytes, of the memory block allocated by a call to calloc, malloc, or realloc.

posted on 2009-01-14 11:01  absolute  阅读(4928)  评论(0编辑  收藏  举报

导航