![]() |
Disk ARchive
2.5.2
Full featured and portable backup and archiving tool
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 00026 00027 00028 #ifndef MEMORY_POOL_HPP 00029 #define MEMORY_POOL_HPP 00030 00031 #include "../my_config.h" 00032 #include <map> 00033 #include "mem_sized.hpp" 00034 #include "erreurs.hpp" 00035 00036 00037 namespace libdar 00038 { 00041 00042 class memory_pool 00043 { 00044 public: 00045 #ifdef LIBDAR_SPECIAL_ALLOC 00046 memory_pool() { carte.clear(); }; 00047 #else 00048 memory_pool() { throw Efeature("Special allocation"); }; 00049 #endif 00050 memory_pool(const memory_pool & ref) { throw SRC_BUG ; }; 00051 const memory_pool & operator = (const memory_pool & ref) { throw SRC_BUG; }; 00052 ~memory_pool() throw(Ebug); 00053 00054 00060 void *alloc(size_t size); 00061 00063 void release(void *ptr); 00064 00066 void garbage_collect(); 00067 00069 bool is_empty() const { return carte.size() == 0; }; 00070 00072 std::string dump() const; 00073 00074 #ifdef LIBDAR_DEBUG_MEMORY 00075 00077 std::string max_percent_full() const; 00078 #endif 00079 00080 private: 00081 00083 union alloc_ptr 00084 { 00085 mem_allocator *ptr;//< points to the mem_allocator that provided the block 00086 U_I alignment__i; //< to properly align the allocated memory block that follows 00087 U_32 alignment_32; //< to properly align the allocated memory block that follows 00088 U_64 alignment_64; //< to properly align the allocated memory block that follows 00089 }; 00090 00091 std::map<U_I, mem_sized *> carte; //< associate a requested block size to the corresponding mem_sized object 00092 #ifdef LIBDAR_DEBUG_MEMORY 00093 std::map<U_I, U_I> count; //< counts the usage of requests per requested block size 00094 #endif 00095 }; 00096 00098 00099 } // end of namespace 00100 00101 #endif