开发者

is it possible to get memory block size allocated by 'new'?

Hello i need to record my heap, but now i am just thinking to overload 'new' operator with my function.

I need to summary the real count开发者_运维问答 bytes of memory that was increased after malloc() or Heap*() or other windows mem* functions

But for now i need to analyze current heap implementation. Is it possible to get blocks size like allocated by HeapAlloc() function - HeapSize() ?

.


I can see that you did not search the documentation.

HeapSize() exists.


Edit On reflection, perhaps you were asking for an alternative to HeapSize() that you can use when you performed allocation yourself with new.

The answer is no. The standard allocation routines don't have anything to grab information about the memory block, because:

  • That's highly implementation-dependent, and
  • You already know the block size (because you specified it in the first place), so what would be the point of the bloat?

In fact HeapSize() is the implementation-dependent function for Windows that does this, but you can only use it when you performed a HeapAlloc().

There's [also non-standard] _msize that can be used with malloc and friends, but new may not use malloc.

Therefore I suggest that you just track the sizes yourself in your allocator.


_msize

According to the documentation it works for calloc,malloc and realloc.

However, at least under Visual Studio, using the default allocator, it works also for new.

It is not a good idea to use it, however, it may do the work for your analysis.

One more thing:

External tools such as VMMap may help for such analysis.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜