How to detect and estimate heap fragmentation in my C++ program?

前端 未结 6 457
鱼传尺愫
鱼传尺愫 2020-12-16 23:11

I\'m developing a VC++ NT service that is meant to operate continuously for many months. It uses VC++ runtime heap intensively. Clearly heap fragmentation can at some point

6条回答
  •  轮回少年
    2020-12-16 23:39

    I guess the best way would be writing your own memory manager (or buying one) that offers this data. Any other way would change the heap itself and thus invalidating the result.

    A strategy that is easier to implement is to allocate memory blocks of different sizes and wait for a failure - but I don't think that's a good way. Anyway - the larger the blocksize was, that did not fail, the less the fragmentation. But depending on the memory manager, allocating the block can change the result.


    Edit: I found a link about the slab allocator (thx for the comment) showing the statistics. It's in German though and the english version of the article does not contain that much information. Use babelfish for translation.

    http://de.wikipedia.org/wiki/Slab_allocator (babelfish version)

    http://www.usenix.org/event/usenix01/full_papers/bonwick/bonwick.pdf

提交回复
热议问题