Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
special_alloc.hpp
Go to the documentation of this file.
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 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00035 
00036 #ifndef SPECIAL_ALLOC_HPP
00037 #define SPECIAL_ALLOC_HPP
00038 
00039 #include "../my_config.h"
00040 #include <iostream>
00041 
00042 #ifdef LIBDAR_SPECIAL_ALLOC
00043 
00044 extern "C"
00045 {
00046 #if HAVE_STDDEF_H
00047 #include <stddef.h>
00048 #else
00049 #if HAVE_STDLIB_H
00050 #include <stdlib.h>
00051 #endif
00052 #endif
00053 } // end extern "C"
00054 
00057 
00058 #define USE_SPECIAL_ALLOC(BASE_TYPE) \
00059         void *operator new(size_t taille) { return special_alloc_new(taille); };                \
00060         void *operator new(size_t taille, BASE_TYPE * & place) { return (void *) place; };      \
00061         void *operator new(size_t taille, void * & place) { return place; };                    \
00062         void operator delete(void *ptr) { special_alloc_delete(ptr); }
00063 
00064 namespace libdar
00065 {
00066         // this following call is to be used in a
00067         // multi-thread environment and is called from
00068         // libdar global initialization function
00069         // this makes libdar thread-safe if POSIX mutex
00070         // are available
00071     extern void special_alloc_init_for_thread_safe();
00072 
00073     extern void *special_alloc_new(size_t taille);
00074     extern void special_alloc_delete(void *ptr);
00075 
00076         // this should be called for sanity and control purposes just before ending the program,
00077         // it will report any block still not yet released
00078     extern void special_alloc_garbage_collect(std::ostream & output);
00079 
00080 
00081 } // end of namespace
00082 
00083 #endif
00084 
00086 
00087 #endif
00088 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines