Is there any benefit to use multiple heaps for memory management purposes?

前端 未结 5 2054
-上瘾入骨i
-上瘾入骨i 2021-02-15 17:37

I am a student of a system software faculty. Now I\'m developing a memory manager for Windows. Here\'s my simple implementation of malloc() and free():

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-15 18:06

    The main reason for using multiple heaps/custom allocators are for better memory control. Usually after lots of new/delete's the memory can get fragmented and loose performance for the application (also the app will consume more memory). Using the memory in a more controlled environment can reduce heap fragmentation.

    Also another usage is for preventing memory leaks in the application, you could just free the entire heap you allocated and you don't need to bother with freeing all the object allocated there.

    Another usage is for tightly allocated objects, if you have for example a list then you could allocate all the nodes in a smaller dedicated heap and the app will gain performance because there will be less cache misses when iterating the nodes.

    Edit: memory management is however a hard topic and in some cases it is not done right. Andrei Alexandrescu had a talk at one point and he said that for some application replacing the custom allocator with the default one increased the performance of the application.

提交回复
热议问题