了解堆上保留内存的大小 [英] Getting to know size of a reserved memory on the heap

查看:95
本文介绍了了解堆上保留内存的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取堆上以前分配的内存大小?

例如:

Is there a way to get the size of previously allocated memory on a heap?
For example:

//pseudo-code

void* p = operator new (sizeof(int) * 3);
unsigned size = getSomeHow(p);  


推荐答案

operator new()可以以任何合理的方式重载,甚至可以不使用运行时堆。

You can't do it at all times, since operator new() can be overloaded in any reasonable way and maybe even without using the runtime heap.

在Visual C ++中使用 malloc()实现 operator new(),可以使用 _msize()

In case operator new() is implemented with malloc() in Visual C++ you can use _msize().

这篇关于了解堆上保留内存的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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