1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #ifndef __MAS_MEMPOOL_H
- #define __MAS_MEMPOOL_H
- #include "Types.h"
- #include "Locks.h"
- #include "MAS_Definition.h"
- NAMESPACE_MAS_BEGIN
- #define MEMPOOL MemPool::Instance()
- class MemPool {
- public:
- static MemPool * Instance();
- static void DestroyInstance();
- TZ_INT Initialize();
- TZ_INT Dispose();
- // return nullptr when failed
- void * AllocAvailMem(TZ_Uint32 expect);
- TZ_INT ReturnFreeMem(void * memBlock, TZ_Uint32 memSize);
- TZ_Uint32 GetAvailCount(TZ_Uint32 expect);
- private:
- MemPool();
- ~MemPool();
- private:
- tzc::Mutex m_lock;
- std::vector<std::list<void *>> m_memDepot;
-
- const TZ_Uint32 MIN_BLOCK_SIZE = 4096;
- const TZ_Uint32 BLOCK_LIST_COUNT = 16;
- static tzc::Mutex _mutex;
- static MemPool * _instance;
- };
- NAMESPACE_MAS_END
- #endif
|