📄 tc3d_policy.h
字号:
/**
* Comet 3D Engine file (c) 2007 - 2008 Tianjie Wei, THSystems Research Group
*
* Released under BSD license, please refer to license.txt for more information
*/
/**
* TODO: Implement the recycling memory allocator
*
*/
#ifndef _TC3D_POLICY_H_
#define _TC3D_POLICY_H_
#include "C3D_Common.h"
namespace C3D
{
namespace Util
{
const TC3D_U32 CC3D_MAX_RECYCLE = 32768; // Maximum recyclable memory size (in bytes)
/**
* Standard memory allocation policy
*
* @Author Tianjie (James) Wei
* @Version 3.0
*/
template < class T >
class TC3D_PolicyStd
{
private:
/**
* Private allocate function to solve DLL boundary issue
*/
inline T *Private_Allocate(TC3D_U32 size)
{
return (T *)MC3D_NEW_MEM(size * sizeof(T));
}
/**
* Private deallocate function to solve DLL boundary issue
*/
inline TC3D_Void Private_Deallocate(T *ptr)
{
MC3D_DELETE_MEM(ptr);
}
public:
/**
* Convert TC3D_PolicyStd<T> to TC3D_PolicyStd<U>
*/
template < class U >
struct Rebind
{
typedef TC3D_PolicyStd<U> Other;
};
public:
/**
* Default constructor
*/
inline explicit TC3D_PolicyStd()
{
}
/**
* Copy constructor
*/
inline explicit TC3D_PolicyStd(const TC3D_PolicyStd &src)
{
}
/**
* TC3D_PolicyStd<U> copy constructor
*/
template < class U >
inline explicit TC3D_PolicyStd(const TC3D_PolicyStd<U> &src)
{
}
/**
* Class destructor
*/
inline ~TC3D_PolicyStd()
{
}
/**
* Allocate an array of objects
*/
inline T *Allocate(TC3D_U32 size)
{
return Private_Allocate(size);
}
/**
* Destroy and array of objects
*/
inline TC3D_Void Deallocate(T *ptr)
{
Private_Deallocate(ptr);
}
};
/**
* Recycling memory allocation policy
*
* @Author Tianjie (James) Wei
* @Version 3.0
*/
template < class T >
class TC3D_PolicyRecycle
{
private:
PC3D_Void *pFreeList;
private:
/**
* Private allocate function to solve DLL boundary issue
*/
DC3D_INLINE T *Private_Allocate(TC3D_U32 size)
{
if(size > CC3D_MAX_RECYCLE)
return (T *)MC3D_NEW_MEM(size * sizeof(T));
return DC3D_NULL;
}
/**
* Private deallocate function to solve DLL boundary issue
*/
DC3D_INLINE TC3D_Void Private_Deallocate(T *ptr)
{
MC3D_DELETE_MEM(ptr);
}
public:
/**
* Convert TC3D_PolicyRecycle<T> to TC3D_PolicyRecycle<U>
*/
template < class U >
struct Rebind
{
typedef TC3D_PolicyRecycle<U> Other;
};
public:
/**
* Default constructor
*/
inline explicit TC3D_PolicyRecycle()
{
}
/**
* Copy constructor
*/
inline explicit TC3D_PolicyRecycle(const TC3D_PolicyRecycle &src)
{
}
/**
* TC3D_PolicyRecycle<U> copy constructor
*/
template < class U >
inline explicit TC3D_PolicyRecycle(const TC3D_PolicyRecycle<U> &src)
{
}
/**
* Class destructor
*/
inline ~TC3D_PolicyRecycle()
{
}
/**
* Allocate an array of objects
*/
inline T *Allocate(TC3D_U32 size)
{
return Private_Allocate(size);
}
/**
* Destroy and array of objects
*/
inline TC3D_Void Deallocate(T *ptr)
{
Private_Deallocate(ptr);
}
};
/**
* Aligned memory allocation policy
*
* @Author Tianjie (James) Wei
* @Version 3.0
*/
template < class T >
class TC3D_PolicyAlign
{
};
};
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -