How much memory was actually allocated from heap for an object?

前端 未结 6 709
渐次进展
渐次进展 2020-12-30 17:09

I have a program that uses way too much memory for allocating numerous small objects on heap. So I would like to investigate into ways to optimize it. The program is compile

6条回答
  •  心在旅途
    2020-12-30 17:27

    You're probably looking to move to a memory pool model (which is what the previous answer about "allocating a large pool" was describing. Because memory pools do not require overhead for each allocation, they offer space savings for large numbers of small objects. If the lifetime of a group of those small objects is short (i.e. you allocate a bunch of small objects then need to get rid of the lot), a memory pool is also much faster because you can just free the pool instead of each object.

    Wikipedia has some info on the technique as well as a link to a few implementations:

    http://en.wikipedia.org/wiki/Memory_pool

    you should be able to find other implementations with a simple web search.

提交回复
热议问题