How to solve Memory Fragmentation

后端 未结 10 1995
天涯浪人
天涯浪人 2020-11-29 16:57

We\'ve occasionally been getting problems whereby our long-running server processes (running on Windows Server 2003) have thrown an exception due to a memory allocation fail

10条回答
  •  我在风中等你
    2020-11-29 17:29

    As usual, you can usually waste memory to gain some speed.

    This technique isn't useful for a general purpose allocator, but it does have it's place.

    Basically, the idea is to write an allocator that returns memory from a pool where all the allocations are the same size. This pool can never become fragmented because any block is as good as another. You can reduce memory wastage by creating multiple pools with different size chunks and pick the smallest chunk size pool that's still greater than the requested amount. I've used this idea to create allocators that run in O(1).

提交回复
热议问题