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

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

memory_pool.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
26
27
28 #ifndef MEMORY_POOL_HPP
29 #define MEMORY_POOL_HPP
30
31 #include "../my_config.h"
32 #include <map>
33 #include "mem_sized.hpp"
34 #include "erreurs.hpp"
35
36
37 namespace libdar
38 {
41
42 class memory_pool
43 {
44 public:
45 #ifdef LIBDAR_SPECIAL_ALLOC
46 memory_pool() { carte.clear(); };
47 #else
48 memory_pool() { throw Efeature("Special allocation"); };
49 #endif
50 memory_pool(const memory_pool & ref) { throw SRC_BUG ; };
51 const memory_pool & operator = (const memory_pool & ref) { throw SRC_BUG; };
52 ~memory_pool() throw(Ebug);
53
54
60 void *alloc(size_t size);
61
63 void release(void *ptr);
64
66 void garbage_collect();
67
69 bool is_empty() const { return carte.size() == 0; };
70
72 std::string dump() const;
73
74 #ifdef LIBDAR_DEBUG_MEMORY
75
77 std::string max_percent_full() const;
78 #endif
79
80 private:
81
83 union alloc_ptr
84 {
85 mem_allocator *ptr;//< points to the mem_allocator that provided the block
86 U_I alignment__i; //< to properly align the allocated memory block that follows
87 U_32 alignment_32; //< to properly align the allocated memory block that follows
88 U_64 alignment_64; //< to properly align the allocated memory block that follows
89 };
90
91 std::map<U_I, mem_sized *> carte; //< associate a requested block size to the corresponding mem_sized object
92 #ifdef LIBDAR_DEBUG_MEMORY
93 std::map<U_I, U_I> count; //< counts the usage of requests per requested block size
94 #endif
95 };
96
98
99 } // end of namespace
100
101 #endif
mem_sized.hpp
defines mem_sized class that holds a variable sized set of fixed sized blocks using class mem_cluster...
erreurs.hpp
contains all the excetion class thrown by libdar
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47