heap.h

来自「c++ 游戏编程中的内存管理源码示例」· C头文件 代码 · 共 53 行

H
53
字号

#ifndef HEAP_H_
#define HEAP_H_


struct AllocHeader;

class Heap
{
public:
    void Initialize();
    
    void * Allocate(size_t bytes);
    static void Deallocate (void * pMem);

    void Activate (const char * name);
    void Deactivate ();

    void AttachTo (Heap * pParent);

    bool IsActive () const { return m_bActive; }
    const char * GetName() const;

    void PrintTreeInfo (int indentLevel = 0) const;
    void PrintInfo (int indentLevel = 0) const;

    int ReportMemoryLeaks (int nBookmark1, int nBookmark2);

    static int GetMemoryBookmark ();

private:
    void Deallocate(AllocHeader * pHeader);
    void GetTreeStats (size_t & totalBytes, size_t & totalPeak, int & totalInstances) const;

    enum { NAMELENGTH = 128 };

    bool   m_bActive;
    char   m_name[NAMELENGTH];
    size_t m_bytesAllocated;
    size_t m_bytesPeak;
    int    m_nInstances;
    AllocHeader * m_pHeadAlloc;

    Heap * m_pParent;
    Heap * m_pFirstChild;
    Heap * m_pNextSibling;
    Heap * m_pPrevSibling;

    static int s_nNextAllocNum;
};


#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?