Initial Commit
This commit is contained in:
66
common/HEAP.HPP
Normal file
66
common/HEAP.HPP
Normal file
@@ -0,0 +1,66 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user