Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Protected Attributes
nsRecycledSingle< OwnerType > Class Template Reference

#include <nsRecycled.h>

Inheritance diagram for nsRecycledSingle< OwnerType >:
Inheritance graph
[legend]
Collaboration diagram for nsRecycledSingle< OwnerType >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

voidoperator new (size_t sz) CPP_THROW_NEW
void operator delete (void *aPtr)

Static Protected Attributes

static nsAutoPtr< char > gPool
static size_t gPoolSize = 0
static PRBool gPoolInUse = PR_FALSE

Detailed Description

template<class OwnerType>
class nsRecycledSingle< OwnerType >

Definition at line 64 of file nsRecycled.h.


Member Function Documentation

template<class OwnerType>
void nsRecycledSingle< OwnerType >::operator delete ( void aPtr) [inline]

Definition at line 114 of file nsRecycled.h.

  {
      if (gPool == aPtr)
      {
         gPoolInUse = PR_FALSE;
         return;
      }
      else
      {
         ::operator delete(aPtr);
      }
  }
template<class OwnerType>
void* nsRecycledSingle< OwnerType >::operator new ( size_t  sz) [inline]

Definition at line 68 of file nsRecycled.h.

  {
      void* result = nsnull;
  
      if (!gPoolInUse)
      {
         if (gPoolSize >= sz)
         {
            result = gPool;
         }
         else
         {
            // Original pool, if any, is deleted by this plain assignment.
            result = ::operator new(sz);
            gPool = (char*)result;
            gPoolSize = sz;
         }
         gPoolInUse = PR_TRUE;
      }
      else
      {
         if (sz > gPoolSize)
         {
            // This would be a good opportunity to throw away our
            // current pool and replace it with this, larger one.

            // Original pool will die as a regular allocated buffer
            // when its time is due.
            gPool.forget();
            result = ::operator new(sz);
            gPool = (char*)result;
            gPoolSize = sz;
         }
         else
         {
            result = ::operator new(sz);
         }
      }
      
     if (result) {
        memset(result, 0, sz);
     }
     
     return result;
  }

Member Data Documentation

template<class OwnerType>
nsAutoPtr< char > nsRecycledSingle< OwnerType >::gPool [static, protected]

Definition at line 128 of file nsRecycled.h.

template<class OwnerType>
PRBool nsRecycledSingle< OwnerType >::gPoolInUse = PR_FALSE [static, protected]

Definition at line 130 of file nsRecycled.h.

template<class OwnerType>
size_t nsRecycledSingle< OwnerType >::gPoolSize = 0 [static, protected]

Definition at line 129 of file nsRecycled.h.


The documentation for this class was generated from the following file: