| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

mem_cluster.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
25
26
27
28 #ifndef MEM_CLUSTER_HPP
29 #define MEM_CLUSTER_HPP
30
31 #include "../my_config.h"
32 #include "mem_allocator.hpp"
33
34
35 namespace libdar
36 {
37
38
41
42 class mem_cluster : public mem_allocator
43 {
44 public:
45 mem_cluster(U_I x_block_size, //< block size that will be allocated from this mem_cluster
46 U_I table_size_64, //< the total number of block in this mem_cluster is table_size_64 * 64
47 mem_manager *x_holder); //< this is the object that holds this mem_cluster object
48 mem_cluster(const mem_cluster & ref): mem_allocator(ref) { throw SRC_BUG; };
49 const mem_cluster & operator = (const mem_cluster & ref) { throw SRC_BUG; };
50 ~mem_cluster();
51
53 bool is_full() const { return available_blocks == 0; };
54
56 bool is_empty() const { return available_blocks == max_available_blocks; };
57
59 void *alloc();
60
62 U_I get_block_size() const { return block_size; };
63
65 std::string dump() const;
66
68 virtual void release(void *ptr);
69
70 #ifdef LIBDAR_DEBUG_MEMORY
71 virtual U_I max_percent_full() const { return (max_available_blocks - min_avail_reached)*100/max_available_blocks; };
72 #else
73 virtual U_I max_percent_full() const { return 0; };
74 #endif
75
76 private:
77 static const U_64 FULL = ~(U_64)(0); //< this is 1111...111 integer in binary notation
78 static const U_64 HALF = (~(U_64)(0)) >> 1; //< this is 0111...111 integer in binary notation
79 static const U_64 LEAD = ~((~(U_64)(0)) >> 1); //< this is 1000...000 integer in binary notation
80
81 // the memory obtained by that object is split in two parts:
82 // - the alloc_table which tells what block is sub-allocated or not
83 // - the alloc_area which contains all the blocks that can be sub-allocated
84 // all this memory is obtained at once and the address to release at object destructor is given by alloc_table
85 // because it takes place at the beginning of the obtained memory
86 char *alloc_area; //< points to the allocatable memory block
87 U_I alloc_area_size; //< size of sub-allocatable memory in bytes (excluding the alloc_table part of the allocated memory used for management)
88 U_I block_size; //< size of requested blocks
89 U_64 *alloc_table; //< maps the blocks of the allocated memory that have been (sub-)allocated
90 U_I alloc_table_size; //< size of the map (in number of U_64 integers)
91 U_I next_free_in_table; //< next U_64 to look at for a request of block allocation
92 U_I available_blocks; //< current number of available block in alloc
93 U_I max_available_blocks; //< max available block in alloc
94 #ifdef LIBDAR_DEBUG_MEMORY
95 U_I min_avail_reached; //< records the max fullfilment reached
96 #endif
97
98 U_I find_free_slot_in(U_I table_integer) const;
99 void set_slot_in(U_I table_integer, U_I bit_offset, bool value);
100 std::string examination_status() const; // debugging, displays the list of allocated blocks that remain
101 };
102
104
105 } // end of namespace
106
107 #endif
mem_allocator.hpp
this is the base class of object that can provide dynamically allocated memory blocks ...
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47