trash.h
来自「跨操作系统的微型中间件」· C头文件 代码 · 共 92 行
H
92 行
/*************************************************************************** * Copyright (C) 2005 by armer song * * armer@szrft.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/#ifndef TRASH_H#define TRASH_H/**@author armer song*/#include <list>#include "OSHeaders.h"template <typename T>class CTrash{public: CTrash() : m_Limit(10) {} virtual ~CTrash() { FreeAll();}public: T * Allocate() { T *pTmp = NULL; if(!m_List.empty()) { pTmp = m_List.front(); m_List.pop_front(); } else { pTmp = new T; if(!pTmp) { //log printf("Allocate failed\n"); } } return pTmp; } void Reclaim(T *p) { if(m_List.size() < m_Limit) m_List.push_back(p); else delete p; } //limit the trash size void SetLimit(UInt32 iCount) { m_Limit = iCount;} //status Bool IsEmpty() {return m_List.empty();} //free void FreeAll() { while(!m_List.empty()) { delete m_List.front(); m_List.pop_front(); } } protected: typedef typename std::list<T*> TrashList; typedef typename std::list<T*>::iterator TrashListIterator; protected: TrashList m_List; UInt32 m_Limit;};#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?