Visual Studio 2010 C++:获取 malloc 分配的内存块大小 [英] Visual Studio 2010 C++: Get size of memory block allocated by malloc

查看:84
本文介绍了Visual Studio 2010 C++:获取 malloc 分配的内存块大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个指向使用 malloc 分配的内存块的指针,我如何获得它的大小?

How can I get, given a pointer to a block of memory allocated with malloc, the size of it?

例如:

void* ptr = malloc( 10 ); //Allocate 10 bytes
printf( "%d", GetMemSize( ptr ) ); //Should print 10

我想这样做是为了调试目的.

I want to do this for debugging purposes.

推荐答案

在 Visual C++ 中,您可以使用 _msize() .

In Visual C++ you can use _msize() for that.

这篇关于Visual Studio 2010 C++:获取 malloc 分配的内存块大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆