# 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 : dar.linux@free.fr
    00020 /*********************************************************************/
    00021 // $Id: special_alloc.hpp,v 1.9 2004/11/07 18:21:38 edrusb Rel $
    00022 //
    00023 /*********************************************************************/
    00024
    00035
    00036 #ifndef SPECIAL_ALLOC_HPP
    00037 #define SPECIAL_ALLOC_HPP
    00038
    00039 #include "../my_config.h"
    00040
    00041 #ifdef LIBDAR_SPECIAL_ALLOC
    00042
    00043 extern "C"
    00044 {
    00045 #if HAVE_STDDEF_H
    00046 #include <stddef.h>
    00047 #else
    00048 #if HAVE_STDLIB_H
    00049 #include <stdlib.h>
    00050 #endif
    00051 #endif
    00052 } // end extern "C"
    00053
    00054 #define USE_SPECIAL_ALLOC(BASE_TYPE) \
    00055         void *operator new(size_t taille) { return special_alloc_new(taille); };                \
    00056         void *operator new(size_t taille, BASE_TYPE * & place) { return (void *) place; };      \
    00057         void *operator new(size_t taille, void * & place) { return place; };                    \
    00058         void operator delete(void *ptr) { special_alloc_delete(ptr); }
    00059
    00060 namespace libdar
    00061 {
    00062         // this following call is to be used in a
    00063         // multi-thread environment and is called from
    00064         // libdar global initialization function
    00065         // this makes the libdar thread-safe if POSIX mutex
    00066         // are available
    00067     extern void special_alloc_init_for_thread_safe();
    00068
    00069     extern void *special_alloc_new(size_t taille);
    00070     extern void special_alloc_delete(void *ptr);
    00071
    00072 } // end of namespace
    00073
    00074 #endif
    00075
    00076 #endif
    00077