MemPoolSGI.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2005-01-17 22:34:01 -0600 (Mon, 17 Jan 2005) $
00011  * Version:       $Revision: 16635 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_MemPoolSGI_h_
00043 #define _VPR_MemPoolSGI_h_
00044 
00045 #include <vpr/vprConfig.h>
00046 #include <iostream>
00047 #include <unistd.h>
00048 #include <ulocks.h>
00049 
00050 
00051 // - Call usinit in new processes created.  Try to overcome limitation on
00052 //   number of users.  Otherwise set to a "big" number.
00053 
00054 
00055 namespace vpr
00056 {
00057 
00076 class MemPoolSGI : public MemPool
00077 {
00078 public:
00079    MemPoolSGI(size_t initialSize = 65536, int numProcs = 8,
00080               char* staticTempName = "/var/tmp/memPoolSGIXXXXXX");
00081 
00082    virtual ~MemPoolSGI()
00083    {
00084       usdetach(arena);
00085       unlink(arenaFileName);
00086       std::cerr << "\nUnlinking: " << arenaFileName << std::endl;
00087    }
00088 
00089 public:
00090    virtual void* allocate(size_t size)
00091    {
00092       void* retval;
00093       retval = usmalloc(size, arena);
00094 
00095       if ( retval == NULL )
00096       {
00097          std::cerr << "MemPoolSGI: Out of memory!!!" << std::endl;
00098       }
00099 
00100       return retval;
00101    }
00102 
00103    virtual void deallocate(void* ptr)
00104    {
00105       usfree(ptr, arena);
00106    }
00107 
00108    virtual void* reallocate(void *ptr, size_t new_sz)
00109    {
00110       return usrealloc(ptr, new_sz, arena);
00111    }
00112 
00113 public:      // Non-virtual functions
00118    usptr_t* getArena()
00119    {
00120       return arena;
00121    }
00122 
00123 public:
00130    static void init(size_t initialSize = 32768, int numProcs = 64,
00131                     char* staticTempName = "/var/tmp/memPoolsArenaXXXXXX");
00132 
00133    void* operator new(size_t sz)
00134    {
00135       std::cerr << "MemPoolSGI::new called. sz:" << sz << "\n";
00136       if ( arenaForMemPools == NULL )
00137       {
00138          init(); // Make sure that we are initialized already.
00139       }
00140 
00141       return usmalloc(sizeof(MemPoolSGI), arenaForMemPools);
00142    }
00143 
00144    void operator delete(void* ptr)
00145    {
00146       usfree(ptr, arenaForMemPools);
00147    }
00148 
00149 private:
00150    usptr_t*   arena;
00151    char*   arenaFileName;
00152 
00153 private:    // Static data for all members -- Must be set before forks!!!!
00154    static usptr_t* arenaForMemPools;
00155    static char* arenaForMemPoolsFileName;
00156 };
00157 
00158 } // End of vpr namespace
00159 
00160 
00161 #endif

Generated on Thu Jan 4 10:52:09 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1