?? tfixedalloc.h
字號:
// TFixedAlloc.h - declarations for fixed block allocator
#ifndef __TFixedAlloc_H__
#define __TFixedAlloc_H__
#include "TPlex.h"
#include "SynchroObject.h"
/////////////////////////////////////////////////////////////////////////////
// TFixedAlloc
class TFixedAlloc
{
// Constructors
public:
TFixedAlloc( TUINT nAllocSize, TUINT nBlockSize = 64 );
// Attributes
TUINT GetAllocSize() { return m_nAllocSize; }
// Operations
public:
void * Alloc(); // return a chunk of memory of nAllocSize
void Free( void * p ); // free chunk of memory returned from Alloc
void FreeAll(); // free everything allocated from this allocator
// Implementation
public:
~TFixedAlloc();
protected:
struct TNode
{
TNode * pNext; // only valid when in free list
};
TUINT m_nAllocSize; // size of each block from Alloc
TUINT m_nBlockSize; // number of blocks to get at a time
TPlex* m_pBlocks; // linked list of blocks (is nBlocks*nAllocSize)
TNode* m_pNodeFree; // first free node (NULL if no free nodes)
TCRITICAL_SECTION m_protect;
};
/*
#ifndef _DEBUG
// DECLARE_FIXED_ALLOC -- used in class definition
#define DECLARE_FIXED_ALLOC(class_name) \
public: \
void* operator new(size_t size) \
{ \
ASSERT(size == s_alloc.GetAllocSize()); \
UNUSED(size); \
return s_alloc.Alloc(); \
} \
void* operator new(size_t, void* p) \
{ return p; } \
void operator delete(void* p) { s_alloc.Free(p); } \
void* operator new(size_t size, LPCSTR, int) \
{ \
ASSERT(size == s_alloc.GetAllocSize()); \
UNUSED(size); \
return s_alloc.Alloc(); \
} \
protected: \
static CFixedAlloc s_alloc \
// IMPLEMENT_FIXED_ALLOC -- used in class implementation file
#define IMPLEMENT_FIXED_ALLOC(class_name, block_size) \
CFixedAlloc class_name::s_alloc(sizeof(class_name), block_size) \
#else //!_DEBUG
#define DECLARE_FIXED_ALLOC(class_name) // nothing in debug
#define IMPLEMENT_FIXED_ALLOC(class_name, block_size) // nothing in debug
#endif //!_DEBUG
*/
#endif //__TFixedAlloc_H__
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -