Disk ARchive  2.5.0
Full featured and portable backup and archiving tool
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
mem_sized.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_SIZED_HPP
29 #define MEM_SIZED_HPP
30 
31 #include "../my_config.h"
32 #include "mem_allocator.hpp"
33 #include "mem_cluster.hpp"
34 #include <list>
35 
36 namespace libdar
37 {
38 
39 
42 
43  class mem_sized : public mem_manager
44  {
45  public:
46  mem_sized(U_I x_block_size);
47  mem_sized(const mem_sized & ref) { throw SRC_BUG; };
48  const mem_sized & operator = (const mem_sized & ref) { throw SRC_BUG; };
49  ~mem_sized();
50 
56  void *alloc(mem_allocator * & ptr);
57 
59  bool is_empty() const;
60 
62  std::string dump() const;
63 
64 #ifdef LIBDAR_DEBUG_MEMORY
65 
67  U_I max_percent_full() const;
68 #endif
69 
71  virtual void push_to_release_list(mem_allocator *ref);
72 
73  private:
74  static const U_I average_table_size = 10240;
75 
76  U_I table_size_64; //< size for clusters
77  std::list<mem_cluster *> clusters; //< the list of owned mem_cluster objects
78  std::list<mem_cluster *>::iterator next_free_in_table; //< points to an mem_cluster that is known to have free slots
79  mem_cluster *pending_release; //< a totally free cluster that can be recycled if all others are full and a new block is requested or freed if another mem_cluster becomes also totally free
80 #ifdef LIBDAR_DEBUG_MEMORY
81  U_I sum_percent; //< summ of all max percent usage obtained before deleting a mem_cluster object (used for statistical purposes)
82  U_I num_cluster; //< number of cluster which sum_percent has been collected from (sum_percent/num_cluster gives the average load of mem_clusters)
83 #endif
84  };
85 
87 
88 } // end of namespace
89 
90 #endif
defines mem_cluster class that holds a fixed set of fixed size allocatable memory blocks ...
this is the base class of object that can provide dynamically allocated memory blocks ...