67 lines
980 B
C++
67 lines
980 B
C++
#ifndef _COMMON_HEAP_HPP_
|
|
#define _COMMON_HEAP_HPP_
|
|
#ifndef _COMMON_WINDOWS_HPP_
|
|
#include <common/windows.hpp>
|
|
#endif
|
|
|
|
class Heap
|
|
{
|
|
public:
|
|
Heap(void);
|
|
Heap(DWORD initialSize);
|
|
virtual ~Heap();
|
|
LPVOID heapAlloc(DWORD allocLength);
|
|
BOOL heapFree(LPVOID pHeapData);
|
|
void heapDestroy(void);
|
|
private:
|
|
enum {PageLength=4096};
|
|
Heap(const Heap& someHeap);
|
|
HANDLE mhHeap;
|
|
};
|
|
|
|
inline
|
|
Heap::Heap(void)
|
|
: mhHeap(::HeapCreate(0,PageLength,0))
|
|
{
|
|
}
|
|
|
|
inline
|
|
Heap::Heap(DWORD initialSize)
|
|
: mhHeap(::HeapCreate(0,initialSize,0))
|
|
{
|
|
}
|
|
|
|
inline
|
|
Heap::~Heap()
|
|
{
|
|
heapDestroy();
|
|
}
|
|
|
|
inline
|
|
LPVOID Heap::heapAlloc(DWORD allocLength)
|
|
{
|
|
if(!mhHeap)return FALSE;
|
|
return ::HeapAlloc(mhHeap,0,allocLength);
|
|
}
|
|
|
|
inline
|
|
BOOL Heap::heapFree(LPVOID pHeapData)
|
|
{
|
|
if(!pHeapData||!mhHeap)return FALSE;
|
|
return ::HeapFree(mhHeap,0,pHeapData);
|
|
}
|
|
|
|
inline
|
|
Heap::Heap(const Heap &/*someHeap*/)
|
|
{
|
|
}
|
|
|
|
inline
|
|
void Heap::heapDestroy(void)
|
|
{
|
|
if(!mhHeap)return;
|
|
::HeapDestroy(mhHeap);
|
|
mhHeap=0;
|
|
}
|
|
#endif
|