Implementing a memory manager in multithreaded C/C++ with dynamically sized memory pool?

前端 未结 4 1147
一生所求
一生所求 2021-02-20 10:08

Background: I\'m developing a multiplatform framework of sorts that will be used as base for both game and util/tool creation. The basic idea

4条回答
  •  醉话见心
    2021-02-20 10:25

    1. Prepare more than one solution and let the user of the framework adopt any particular one. Policy classes to the generic allocator you develop would do this nicely.

    2. A nice way to get around this is to wrap up pointers in a class with overloaded * operator. Make the internal data of that class only an index to the memory pool. Now, you can just change the index quickly after a background thread copies the data over.

    3. Most good C++ libraries support allocators and you should implement one. You can also overload the global new so your version gets used. And keep in mind that you generally won't need to think about a library allocating or deallocating a large amount of data, which is generally a responsibility of client code.

提交回复
热议问题