Improvements for this C++ stack allocator?

前端 未结 4 2006
广开言路
广开言路 2020-12-31 21:42

Any suggestions for my stack based allocator? (Except for suggestions to use a class with private/public members)

struct Heap
{
    void* heap_start;
    voi         


        
4条回答
  •  一生所求
    2020-12-31 22:28

    You've implemented a stack based allocator. You can't free up without leaving gaps. Usually a pool refers to a block of contiguous memory with fixed sized slots, which are doubly linked to allow constant time add and delete.

    Here's one you can use as a guide. It's along the same lines as yours but includes basic iterators over allocated nodes, and uses templates to be type aware.

提交回复
热议问题