#include <vpr/md/SPROC/SharedMem/MemPoolSGI.h>
Inheritance diagram for vpr::MemPoolSGI:


Public Member Functions | |
| MemPoolSGI (size_t initialSize=65536, int numProcs=8, char *staticTempName="/var/tmp/memPoolSGIXXXXXX") | |
| virtual | ~MemPoolSGI () |
| virtual void * | allocate (size_t size) |
| virtual void | deallocate (void *ptr) |
| virtual void * | reallocate (void *ptr, size_t new_sz) |
| usptr_t * | getArena () |
| Use with extreme caution. | |
| void * | operator new (size_t sz) |
| void | operator delete (void *ptr) |
Static Public Member Functions | |
| static void | init (size_t initialSize=32768, int numProcs=64, char *staticTempName="/var/tmp/memPoolsArenaXXXXXX") |
| Function must be called before any vpr::MemPools are created. | |
Used to control allocation and deallocation from a "memory pool."
This class is for use exclusively within VPR. More specifically, it is only for use by the SPROC threading subsystem.
Clients should create memory pools as needed. Then, when objects are created, they can pass a pool as a parameter to the new (if the object is a derived from vprMemory).
Definition at line 76 of file MemPoolSGI.h.
| vpr::MemPoolSGI::MemPoolSGI | ( | size_t | initialSize = 65536, |
|
| int | numProcs = 8, |
|||
| char * | staticTempName = "/var/tmp/memPoolSGIXXXXXX" | |||
| ) |
Definition at line 51 of file MemPoolSGI.cpp.
00053 { 00054 std::cerr.setf(std::ios::showbase); 00055 std::cerr << "\nMemPoolSGI: Allocating arena (" << initialSize << " bytes, " 00056 << numProcs << " procs, " << std::hex << this << std::dec 00057 << ")\n" << std::flush; 00058 00059 usconfig(CONF_INITUSERS, numProcs); 00060 usconfig(CONF_INITSIZE, initialSize); 00061 usconfig(CONF_AUTOGROW, 1); // Default, but we set anyway 00062 //#ifdef DEBUG_VJ 00063 usconfig(CONF_LOCKTYPE, US_DEBUGPLUS); // what type of lock information 00064 //#endif 00065 00066 //static char* staticTempName = "/var/tmp/memPoolSGIXXXXXX"; // Do it this way because mktemp overwrite's the variable 00067 char* tempName = new char[strlen(staticTempName)+1]; // Therefore we need to use a non-static variable 00068 strcpy(tempName, staticTempName); 00069 00070 arena = usinit(mktemp(tempName)); // Allocate the arena 00071 00072 arenaFileName = tempName; // So we know where the file is 00073 //delete tempName; // Delete the temporary file name 00074 00075 if ( arena == NULL ) 00076 { 00077 perror("ERROR: PoolSGI::MemPoolSGI"); 00078 } 00079 00080 std::cerr << " " << arenaFileName << ", " << "arena: " << std::hex << arena 00081 << std::dec << std::endl; 00082 std::cerr.unsetf(std::ios::showbase); 00083 }
| virtual vpr::MemPoolSGI::~MemPoolSGI | ( | ) | [inline, virtual] |
Definition at line 82 of file MemPoolSGI.h.
00083 { 00084 usdetach(arena); 00085 unlink(arenaFileName); 00086 std::cerr << "\nUnlinking: " << arenaFileName << std::endl; 00087 }
| virtual void* vpr::MemPoolSGI::allocate | ( | size_t | size | ) | [inline, virtual] |
Implements vpr::MemPool.
Definition at line 90 of file MemPoolSGI.h.
Referenced by vpr::BarrierSGI::BarrierSGI(), vpr::MutexSGI::MutexSGI(), and vpr::SemaphoreSGI::SemaphoreSGI().
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 }
| virtual void vpr::MemPoolSGI::deallocate | ( | void * | ptr | ) | [inline, virtual] |
Implements vpr::MemPool.
Definition at line 103 of file MemPoolSGI.h.
Referenced by vpr::BarrierSGI::~BarrierSGI(), vpr::MutexSGI::~MutexSGI(), and vpr::SemaphoreSGI::~SemaphoreSGI().
| virtual void* vpr::MemPoolSGI::reallocate | ( | void * | ptr, | |
| size_t | new_sz | |||
| ) | [inline, virtual] |
| usptr_t* vpr::MemPoolSGI::getArena | ( | ) | [inline] |
Use with extreme caution.
Definition at line 118 of file MemPoolSGI.h.
Referenced by vpr::BarrierSGI::BarrierSGI(), vpr::MutexSGI::MutexSGI(), vpr::SemaphoreSGI::SemaphoreSGI(), vpr::MutexSGI::~MutexSGI(), and vpr::SemaphoreSGI::~SemaphoreSGI().
| void vpr::MemPoolSGI::init | ( | size_t | initialSize = 32768, |
|
| int | numProcs = 64, |
|||
| char * | staticTempName = "/var/tmp/memPoolsArenaXXXXXX" | |||
| ) | [static] |
Function must be called before any vpr::MemPools are created.
Automatically called by the first new with default values if not called previously. Function to initialize any STATIC data structures.
Definition at line 85 of file MemPoolSGI.cpp.
Referenced by operator new().
00087 { 00088 if ( arenaForMemPools == NULL ) 00089 { 00090 std::cerr << "\nMemPoolSGI: Allocating Base Arena for ALL MemPoolSGI's.\n" 00091 << initialSize << " bytes, " << numProcs << " procs" 00092 << "\n" << std::flush; 00093 00094 usconfig(CONF_INITUSERS, numProcs); 00095 usconfig(CONF_INITSIZE, initialSize); 00096 usconfig(CONF_AUTOGROW, 1); // Default, but we set anyway 00097 00098 char* tempName = strdup (staticTempName); // make mutable copy for mktemp 00099 00100 arenaForMemPools = usinit(mktemp(tempName)); 00101 unlink(tempName); 00102 00103 if ( arenaForMemPools == NULL ) 00104 { 00105 perror("ERROR: MemPoolSGI::init. Was not able to get an arena!!!!"); 00106 } 00107 arenaForMemPoolsFileName = (char*)usmalloc(strlen(staticTempName)+1, arenaForMemPools); 00108 strcpy(arenaForMemPoolsFileName, tempName); 00109 free (tempName); 00110 00111 std::cerr.setf(std::ios::showbase); 00112 std::cerr << " " << arenaForMemPoolsFileName << ", " << "arena: " 00113 << std::hex << arenaForMemPools << std::dec << std::endl; 00114 std::cerr.unsetf(std::ios::showbase); 00115 } 00116 else 00117 { 00118 std::cerr << "Tried to re-init the Base Arena for ALL MemPoolSGI's" 00119 << std::endl; 00120 } 00121 }
| void* vpr::MemPoolSGI::operator new | ( | size_t | sz | ) | [inline] |
Definition at line 133 of file MemPoolSGI.h.
References init().
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 }
| void vpr::MemPoolSGI::operator delete | ( | void * | ptr | ) | [inline] |
1.5.1