#pragma once #include "Container.h" /*************************************************************** 容器,使用小内存管理 ***************************************************************/ template CList::CList(CBufferAllocator* pAllocator) { wylib::container::CBaseLinkedList(); if (pAllocator) m_pAllocator = pAllocator; #ifndef __ROBOT_CLIENT__ else m_pAllocator = GetLogicServer()->GetBuffAllocator(); #endif } template CList::~CList() { CBaseLinkedList::clear(); } template CLinkedNode* CList::allocNode() { CLinkedNode* result = (CLinkedNode*)m_pAllocator->AllocBuffer(sizeof(CLinkedNode)); if(result == NULL ) return NULL; if(result) { new(&result->m_Data)DATA();//placement new } return result; } template VOID CList::freeNode(CLinkedNode *pNode) { if(pNode == NULL) return; if(pNode) { (&pNode->m_Data)->~DATA(); } m_pAllocator->FreeBuffer(PVOID(pNode)); } template CVector::CVector(CBufferAllocator* pAllocator) { wylib::container::CBaseList() ; if (pAllocator) m_pAllocator = pAllocator; #ifndef __ROBOT_CLIENT__ else m_pAllocator = GetLogicServer()->GetBuffAllocator(); #endif } template CVector::~CVector() { empty(); } template void CVector::empty() { CBaseList::clear(); this->m_tMaxCount = 0; if(this->m_pData) { m_pAllocator->FreeBuffer(PVOID(this->m_pData)); } this->m_pData = NULL; } template void CVector::reserve(INT_PTR count) { if ( count > this->m_tCount && count != this->m_tMaxCount ) { PVOID *pData=(PVOID *) m_pAllocator->AllocBuffer(sizeof(DATA) * count); if(this->m_pData && this->m_tMaxCount >0) { memcpy(pData,this->m_pData,sizeof(DATA)*this->m_tMaxCount); m_pAllocator->FreeBuffer(PVOID(this->m_pData)); } if (this->m_pData && this->m_tMaxCount <= 0) { Assert(FALSE); } this->m_pData = (DATA*)pData; this->m_tMaxCount = count; } }