![]() |
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 00025 00026 00027 00028 #ifndef MEM_CLUSTER_HPP 00029 #define MEM_CLUSTER_HPP 00030 00031 #include "../my_config.h" 00032 #include "mem_allocator.hpp" 00033 00034 00035 namespace libdar 00036 { 00037 00038 00041 00042 class mem_cluster : public mem_allocator 00043 { 00044 public: 00045 mem_cluster(U_I x_block_size, //< block size that will be allocated from this mem_cluster 00046 U_I table_size_64, //< the total number of block in this mem_cluster is table_size_64 * 64 00047 mem_manager *x_holder); //< this is the object that holds this mem_cluster object 00048 mem_cluster(const mem_cluster & ref): mem_allocator(ref) { throw SRC_BUG; }; 00049 const mem_cluster & operator = (const mem_cluster & ref) { throw SRC_BUG; }; 00050 ~mem_cluster(); 00051 00053 bool is_full() const { return available_blocks == 0; }; 00054 00056 bool is_empty() const { return available_blocks == max_available_blocks; }; 00057 00059 void *alloc(); 00060 00062 U_I get_block_size() const { return block_size; }; 00063 00065 std::string dump() const; 00066 00068 virtual void release(void *ptr); 00069 00070 #ifdef LIBDAR_DEBUG_MEMORY 00071 virtual U_I max_percent_full() const { return (max_available_blocks - min_avail_reached)*100/max_available_blocks; }; 00072 #else 00073 virtual U_I max_percent_full() const { return 0; }; 00074 #endif 00075 00076 private: 00077 static const U_64 FULL = ~(U_64)(0); //< this is 1111...111 integer in binary notation 00078 static const U_64 HALF = (~(U_64)(0)) >> 1; //< this is 0111...111 integer in binary notation 00079 static const U_64 LEAD = ~((~(U_64)(0)) >> 1); //< this is 1000...000 integer in binary notation 00080 00081 // the memory obtained by that object is split in two parts: 00082 // - the alloc_table which tells what block is sub-allocated or not 00083 // - the alloc_area which contains all the blocks that can be sub-allocated 00084 // all this memory is obtained at once and the address to release at object destructor is given by alloc_table 00085 // because it takes place at the beginning of the obtained memory 00086 char *alloc_area; //< points to the allocatable memory block 00087 U_I alloc_area_size; //< size of sub-allocatable memory in bytes (excluding the alloc_table part of the allocated memory used for management) 00088 U_I block_size; //< size of requested blocks 00089 U_64 *alloc_table; //< maps the blocks of the allocated memory that have been (sub-)allocated 00090 U_I alloc_table_size; //< size of the map (in number of U_64 integers) 00091 U_I next_free_in_table; //< next U_64 to look at for a request of block allocation 00092 U_I available_blocks; //< current number of available block in alloc 00093 U_I max_available_blocks; //< max available block in alloc 00094 #ifdef LIBDAR_DEBUG_MEMORY 00095 U_I min_avail_reached; //< records the max fullfilment reached 00096 #endif 00097 00098 U_I find_free_slot_in(U_I table_integer) const; 00099 void set_slot_in(U_I table_integer, U_I bit_offset, bool value); 00100 std::string examination_status() const; // debugging, displays the list of allocated blocks that remain 00101 }; 00102 00104 00105 } // end of namespace 00106 00107 #endif