Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

mySharedAllocator.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 
00015  * for the software may use this file in accordance with that specific license
00016  *
00017  */
00018 
00019 #ifndef mySharedMemoryAllocatorHEADER
00020 #define mySharedMemoryAllocatorHEADER
00021 
00022 #include <PsMomeController.h>
00023 #include <PsnSharedMemoryManager.h>
00024 #include <PsnMemoryElementDescriptor.h>
00025 
00027 class mySharedAllocator {
00028 public:
00029    typedef size_t size_type;
00030    typedef ptrdiff_t difference_type;
00031    typedef void * pointer;
00032 
00036    mySharedAllocator () throw();
00038    mySharedAllocator(const mySharedAllocator &) throw();
00040    ~mySharedAllocator() throw();
00042       
00044    static pointer allocate(size_type n, const void * = 0) {
00045       PsnSharedMemoryManager * STLManager = PsMomeController::STLSharedMemoryManager;
00046       STLManager->lockIfNeeded();
00047       pointer resul(STLManager->mmalloc(n));
00048       STLManager->unlockIfNeeded();
00049       return resul;
00050    }
00051 
00053    static void deallocate(pointer p, size_type n) {
00054       PsnSharedMemoryManager * STLManager = PsMomeController::STLSharedMemoryManager;
00055       STLManager->lockIfNeeded();
00056       STLManager->mfree(p,n);
00057       STLManager->unlockIfNeeded();
00058    }
00059 
00060 };
00061 
00063 template <typename T> class mySharedAllocatorT;
00064 
00065 
00067 template<>
00068 class mySharedAllocatorT<void> {
00069 public:
00070   typedef void*       pointer;
00071   typedef const void* const_pointer;
00072   typedef void        value_type;
00073 
00074   template <typename _Tp1> struct rebind {
00075     typedef mySharedAllocatorT<_Tp1> other;
00076   };
00077 };
00078 
00080 template <typename T> 
00081 class mySharedAllocatorT {
00082 public:
00083    typedef size_t size_type;
00084    typedef ptrdiff_t difference_type;
00085    typedef T * pointer;
00086    typedef const T* const_pointer;
00087    typedef T& reference;
00088    typedef const T & const_reference;
00089    typedef T value_type;
00090 
00091    template <typename T1> struct rebind {
00092       typedef mySharedAllocatorT<T1> other;
00093    };
00094 
00098    mySharedAllocatorT () throw() {
00099       //cerr<<"mySharedAllocatorT"<<endl;
00100    };
00102    mySharedAllocatorT(const mySharedAllocatorT &) throw() {
00103       //cerr<<"mySharedAllocatorT(const mySharedAllocatorT &)"<<endl;
00104    };
00106    template <typename U> mySharedAllocatorT(const mySharedAllocatorT<U> &) throw() {
00107       //cerr<<"mySharedAllocatorT(const mySharedAllocatorT<U> &)"<<endl;   
00108    }
00110    ~mySharedAllocatorT() throw() {
00111       //cerr<<"~mySharedAllocatorT()"<<endl;
00112    };
00114    
00116    pointer address(reference x) const {
00117       return &x;
00118    }
00119 
00121    const_pointer address(const_reference x) const {
00122       return &x;
00123    }
00124    
00126    pointer allocate(size_type n, mySharedAllocatorT<void>::const_pointer hint  = 0) {
00127       if(n<0) {
00128          n=0;
00129       }
00130       PsnSharedMemoryManager * STLManager = PsMomeController::STLSharedMemoryManager;
00131       //cerr<<"mySharedAllocator::allocate avant lock()"<<endl;
00132       STLManager->lockIfNeeded();
00133       //cerr<<"mySharedAllocator::allocate après lock()"<<endl;
00134       pointer resul=(pointer)PsMomeController::STLSharedMemoryManager->mmalloc(n*sizeof(T));
00135       STLManager->unlockIfNeeded();
00136       return resul;
00137    }
00138 
00140    void deallocate(pointer p, size_type n) {
00141       PsnSharedMemoryManager * STLManager = PsMomeController::STLSharedMemoryManager;
00142       STLManager->lockIfNeeded();
00143       PsMomeController::STLSharedMemoryManager->mfree((void *)p,n*sizeof(T));
00144       STLManager->unlockIfNeeded();
00145    }
00146 
00148    size_type max_size() const throw() {
00149       cerr<<"mySharedAllocatorT::max_size"<<endl;
00150       return 16374;
00151    }
00152 
00154    void construct(pointer p, const T& val) {
00155       cerr<<"mySharedAllocatorT::construct"<<endl;
00156       return new((void *)p) T(val);
00157    };
00158 
00160    void destroy(pointer p) {
00161       cerr<<"mySharedAllocatorT::destroy"<<endl;
00162       ((T*)p)->~T() ;
00163    }
00164 };
00165 
00166 
00167 #endif
00168 

logo OpenMask

Documentation generated on Mon Nov 25 15:24:59 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001