Disk ARchive  2.4.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
special_alloc.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 
32 
33 #ifndef SPECIAL_ALLOC_HPP
34 #define SPECIAL_ALLOC_HPP
35 
36 #include "../my_config.h"
37 #include <iostream>
38 #include <new>
39 
40 #ifdef LIBDAR_SPECIAL_ALLOC
41 
42 extern "C"
43 {
44 #if HAVE_STDDEF_H
45 #include <stddef.h>
46 #else
47 #if HAVE_STDLIB_H
48 #include <stdlib.h>
49 #endif
50 #endif
51 } // end extern "C"
52 
55 
56 #define USE_SPECIAL_ALLOC(BASE_TYPE) \
57  void *operator new(size_t taille) { return special_alloc_new(taille); }; \
58  void *operator new(size_t taille, const std::nothrow_t& nothrow_constant) { return special_alloc_new(taille); }; \
59  void *operator new(size_t taille, BASE_TYPE * & place) { return (void *) place; }; \
60  void *operator new(size_t taille, void * & place) { return place; }; \
61  void operator delete(void *ptr) throw() { special_alloc_delete(ptr); } \
62  void operator delete(void* ptr, const std::nothrow_t& nothrow_constant) throw() { special_alloc_delete(ptr); }
63 
64 namespace libdar
65 {
66  // this following call is to be used in a
67  // multi-thread environment and is called from
68  // libdar global initialization function
69  // this makes libdar thread-safe if POSIX mutex
70  // are available
71  extern void special_alloc_init_for_thread_safe();
72 
73  extern void *special_alloc_new(size_t taille);
74  extern void special_alloc_delete(void *ptr);
75 
76  // this should be called for sanity and control purposes just before ending the program,
77  // it will report any block still not yet released
78  extern void special_alloc_garbage_collect(std::ostream & output);
79 
80 
81 } // end of namespace
82 
83 #endif
84 
86 
87 #endif
88