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

HeapStackTop Class Reference

personnal version of the HeapStackTop class by Nathan C.Myers described in the july and august 1993 articles of C++ report entitled MemoryManagement in C++ More...

#include <PsnNew.h>

List of all members.

Public Methods

 HeapStackTop (PsnMemoryManager *newTop)
 constructor install newTop as the new default memory allocator

virtual ~HeapStackTop ()
 destructor reinstall _oldMemoryManager as the default memory allocator

void * operator new (size_t)
 redefine allocation for fast allocation - deallocation cycles

void operator delete (void *, size_t)

Static Public Methods

pthread_key_t initialiseGlobalMemoryManagerKey ()
 a function to enble correct initialisation of keys

pthread_key_t initialiseFreedKey ()
 a function to enble correct initialisation of keys

PsnSystemMemoryManagergetSystemMemoryManager ()
 a function to get to the system memory manager wich is wrapped by the PsnSharedMemoryManager class


Static Public Attributes

pthread_key_t globalMemoryManagerKey = HeapStackTop::initialiseGlobalMemoryManagerKey ()
 A key for a thread to access it's current memory manager.


Protected Attributes

void * _oldMemoryManager
 the old memoryManager replaced during creation of this HeapStackTop


Static Protected Attributes

pthread_key_t freedKey = HeapStackTop::initialiseFreedKey ()
 A key for a thread to access it's last freed memory area for an object of HeapStackTop type.


Friends

class PsController
 declare the controler as a friend so that freedKey can be properly destroyed


Detailed Description

personnal version of the HeapStackTop class by Nathan C.Myers described in the july and august 1993 articles of C++ report entitled MemoryManagement in C++

Definition at line 30 of file PsnNew.h.


Constructor & Destructor Documentation

HeapStackTop::HeapStackTop PsnMemoryManager   newTop
 

constructor install newTop as the new default memory allocator

Definition at line 98 of file PsnNew.cxx.

References _oldMemoryManager, globalMemoryManagerKey, and initialiseGlobalMemoryManagerKey().

00098                                                     {
00099    static pthread_key_t bidon = HeapStackTop::initialiseGlobalMemoryManagerKey () ;
00100 #ifdef _DEBUGMEMORYMANAGEMENT
00101    cerr<<"HeapStackTop::HeapStackTop"<<endl;
00102 #endif
00103    _oldMemoryManager = pthread_getspecific( globalMemoryManagerKey ) ;
00104    pthread_setspecific ( globalMemoryManagerKey , newTop );
00105 }

HeapStackTop::~HeapStackTop   [virtual]
 

destructor reinstall _oldMemoryManager as the default memory allocator

Definition at line 109 of file PsnNew.cxx.

References _oldMemoryManager, globalMemoryManagerKey, and initialiseGlobalMemoryManagerKey().

00109                             {
00110    static pthread_key_t bidon = HeapStackTop::initialiseGlobalMemoryManagerKey () ;
00111 #ifdef _DEBUGMEMORYMANAGEMENT
00112    cerr<<"HeapStackTop::~HeapStackTop"<<endl;
00113 #endif
00114    pthread_setspecific ( globalMemoryManagerKey , _oldMemoryManager );
00115 }


Member Function Documentation

PsnSystemMemoryManager * HeapStackTop::getSystemMemoryManager   [static]
 

a function to get to the system memory manager wich is wrapped by the PsnSharedMemoryManager class

Definition at line 24 of file PsnNew.cxx.

Referenced by PsnMultiThreadedScheduler::_threadContainer(), PsnMultiThreadedBenchmarkingScheduler::_threadContainer(), PsOutput< Type >::getDateOfLastExactValue(), PsOutput< Type >::getLastExactValue(), initialiseGlobalMemoryManagerKey(), PsOutput< Type >::localGet(), PsOutput< Type >::localInsert(), PsnMemoryElementDescriptor::operator new(), PsMultiThreadedPvmController::run(), PsMultiThreadedController::run(), and PsnMemoryManager::whichMemoryManager().

00025 {
00026    // using new causes an infinite loop, as new needs getSystmeMemoryManager
00027    // 
00028    static PsnSystemMemoryManager toto ; 
00029    return & toto ;
00030 }

pthread_key_t HeapStackTop::initialiseFreedKey   [static]
 

a function to enble correct initialisation of keys

Definition at line 52 of file PsnNew.cxx.

References freedKey.

Referenced by operator delete(), and operator new().

00053 {
00054    static bool done = false ;
00055    if ( ! done )
00056       {
00057          pthread_key_t res ;
00058          pthread_key_create(&res, NULL) ;
00059          pthread_setspecific ( res , NULL );
00060          done = true ;
00061          freedKey =res ;         
00062          return res ;
00063       }
00064    else 
00065       {
00066          return freedKey ;
00067       }
00068 }

pthread_key_t HeapStackTop::initialiseGlobalMemoryManagerKey   [static]
 

a function to enble correct initialisation of keys

Definition at line 32 of file PsnNew.cxx.

References getSystemMemoryManager(), and globalMemoryManagerKey.

Referenced by HeapStackTop(), operator new(), and ~HeapStackTop().

00033 {
00034    static bool done = false ;
00035    if ( ! done )
00036       {
00037          pthread_key_t res ;
00038          pthread_key_create(&res, NULL) ;
00039          pthread_setspecific ( res , getSystemMemoryManager() );
00040          done = true ;
00041          globalMemoryManagerKey = res ;
00042          return res ;
00043       }
00044    else 
00045       {
00046          return globalMemoryManagerKey ;
00047       }
00048 }

void HeapStackTop::operator delete void *   ,
size_t   
 

Definition at line 87 of file PsnNew.cxx.

References freedKey, and initialiseFreedKey().

00087                                                           {
00088    static pthread_key_t bidon = initialiseFreedKey () ;
00089    void * freed = pthread_getspecific(freedKey) ;
00090    if (freed!=NULL) {
00091       ::operator delete (freed);
00092    }
00093    pthread_setspecific(freedKey, addr);
00094 }

void * HeapStackTop::operator new size_t   
 

redefine allocation for fast allocation - deallocation cycles

Definition at line 75 of file PsnNew.cxx.

References freedKey, initialiseFreedKey(), and operator new().

00075                                               {
00076    static pthread_key_t bidon = initialiseFreedKey () ;
00077    void * freed = pthread_getspecific(freedKey) ;
00078 
00079    if (freed!=NULL) {
00080       return freed;
00081    }
00082    else {
00083       return ::operator new(size);
00084    }
00085 }


Friends And Related Function Documentation

friend class PsController [friend]
 

declare the controler as a friend so that freedKey can be properly destroyed

Definition at line 60 of file PsnNew.h.


Member Data Documentation

void* HeapStackTop::_oldMemoryManager [protected]
 

the old memoryManager replaced during creation of this HeapStackTop

Definition at line 63 of file PsnNew.h.

Referenced by HeapStackTop(), and ~HeapStackTop().

pthread_key_t HeapStackTop::freedKey = HeapStackTop::initialiseFreedKey () [static, protected]
 

A key for a thread to access it's last freed memory area for an object of HeapStackTop type.

Definition at line 71 of file PsnNew.cxx.

Referenced by initialiseFreedKey(), operator delete(), and operator new().

pthread_key_t HeapStackTop::globalMemoryManagerKey = HeapStackTop::initialiseGlobalMemoryManagerKey () [static]
 

A key for a thread to access it's current memory manager.

Use should be implicit, through creation and deletion of heapStackTop objects

Definition at line 70 of file PsnNew.cxx.

Referenced by HeapStackTop(), initialiseGlobalMemoryManagerKey(), PsnRelaxedMemoryManager::mLatencyMalloc(), PsnRelaxedMemoryManager::mmallocForOnce(), operator delete(), PsnMemoryElementDescriptor::operator delete(), operator new(), PsnMomeArray< T >::PsnMomeArray(), ~HeapStackTop(), and PsnMemoryManager::~PsnMemoryManager().


The documentation for this class was generated from the following files:
logo OpenMask

Documentation generated on Mon Nov 25 15:26:02 2002

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