Eneboo - Documentación para desarrolladores
|
00001 // -*- C++ -*- 00002 00003 /* 00004 00005 Heap Layers: An Extensible Memory Allocation Infrastructure 00006 00007 Copyright (C) 2000-2003 by Emery Berger 00008 http://www.cs.umass.edu/~emery 00009 emery@cs.umass.edu 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; either version 2 of the License, or 00014 (at your option) any later version. 00015 00016 This program is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with this program; if not, write to the Free Software 00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 00025 */ 00026 00027 00028 #ifndef _ADAPT_H_ 00029 #define _ADAPT_H_ 00030 00037 namespace HL { 00038 00039 template <class Dictionary, class SuperHeap> 00040 class AdaptHeap : public SuperHeap { 00041 public: 00042 00044 inline void * malloc (const size_t) { 00045 void * ptr = (Entry *) dict.get(); 00046 return ptr; 00047 } 00048 00050 inline void free (void * ptr) { 00051 Entry * entry = (Entry *) ptr; 00052 dict.insert (entry); 00053 } 00054 00056 inline int remove (void * ptr) { 00057 dict.remove ((Entry *) ptr); 00058 return 1; 00059 } 00060 00062 inline void clear (void) { 00063 Entry * ptr; 00064 while ((ptr = (Entry *) dict.get()) != NULL) { 00065 SuperHeap::free (ptr); 00066 } 00067 dict.clear(); 00068 SuperHeap::clear(); 00069 } 00070 00071 00072 private: 00073 00075 Dictionary dict; 00076 00077 class Entry : public Dictionary::Entry {}; 00078 }; 00079 00080 } 00081 00082 #endif // _ADAPT_H_