FbxHungryAllocator Class Reference

FbxHungryAllocator Class Reference

#include <fbxcontainerallocators.h>

Class Description

This allocator only frees the allocated memory when it is deleted.

This is a good allocator for building dictionaries, where we only add things to a container, but never remove them.

Definition at line 82 of file fbxcontainerallocators.h.

Public Member Functions

 FbxHungryAllocator (size_t pRecordSize)
 
 FbxHungryAllocator (const FbxHungryAllocator &pOther)
 
 ~FbxHungryAllocator ()
 
void Reserve (const size_t pRecordCount)
 
void * AllocateRecords (const size_t pRecordCount=1)
 
void FreeMemory (void *)
 
size_t GetRecordSize () const
 
FbxHungryAllocatoroperator= (const FbxHungryAllocator &pOther)
 

Constructor & Destructor Documentation

FbxHungryAllocator ( size_t  pRecordSize)
inline

Definition at line 85 of file fbxcontainerallocators.h.

85  :
86  mRecordSize(pRecordSize),
87  mRecordPoolSize(0),
88  mData(NULL)
89  {
90  }
#define NULL
Definition: fbxarch.h:210
FbxHungryAllocator ( const FbxHungryAllocator pOther)
inline

Definition at line 92 of file fbxcontainerallocators.h.

92  :
93  mRecordSize(pOther.mRecordSize),
94  mRecordPoolSize(pOther.mRecordPoolSize),
95  mData(NULL)
96  {
97  }
#define NULL
Definition: fbxarch.h:210
~FbxHungryAllocator ( )
inline

Definition at line 99 of file fbxcontainerallocators.h.

100  {
101  MemoryBlock* lCurrent = mData;
102  MemoryBlock* lNext = lCurrent ? lCurrent->mNextBlock : 0;
103  while (lCurrent)
104  {
105  FbxDelete(lCurrent);
106  lCurrent = lNext;
107  lNext = lCurrent ? lCurrent->mNextBlock : 0;
108  }
109  }
void FbxDelete(T *p)
Deletion policy for pointer template classes that uses the FbxDelete() function.
Definition: fbxnew.h:341

Member Function Documentation

void Reserve ( const size_t  pRecordCount)
inline

Definition at line 111 of file fbxcontainerallocators.h.

112  {
113  MemoryBlock* lMem = FbxNew< MemoryBlock >(pRecordCount* mRecordSize);
114  lMem->mNextBlock = mData;
115  mData = lMem;
116  mRecordPoolSize += pRecordCount;
117  }
void* AllocateRecords ( const size_t  pRecordCount = 1)
inline

Definition at line 119 of file fbxcontainerallocators.h.

120  {
121  MemoryBlock* lBlock = mData;
122  void* lRecord = NULL;
123 
124  while( (lBlock != NULL) && ((lRecord = lBlock->GetChunk(pRecordCount * mRecordSize)) == NULL) )
125  {
126  lBlock = lBlock->mNextBlock;
127  }
128 
129  if( lRecord == NULL )
130  {
131  size_t lNumRecordToAllocate = mRecordPoolSize / 8 == 0 ? 2 : mRecordPoolSize / 8;
132  if( lNumRecordToAllocate < pRecordCount )
133  {
134  lNumRecordToAllocate = pRecordCount;
135  }
136  Reserve(lNumRecordToAllocate);
137  lRecord = AllocateRecords(pRecordCount);
138  }
139  return lRecord;
140  }
#define NULL
Definition: fbxarch.h:210
void Reserve(const size_t pRecordCount)
void * AllocateRecords(const size_t pRecordCount=1)
void FreeMemory ( void *  )
inline

Definition at line 142 of file fbxcontainerallocators.h.

143  {
144  // "Hungry": release memory only when the allocator is destroyed.
145  }
size_t GetRecordSize ( ) const
inline

Definition at line 147 of file fbxcontainerallocators.h.

148  {
149  return mRecordSize;
150  }
FbxHungryAllocator& operator= ( const FbxHungryAllocator pOther)
inline

Definition at line 152 of file fbxcontainerallocators.h.

153  {
154  if( this != &pOther )
155  {
156  // The next call to AllocateRecords() may skip over currently reserved
157  // records if the size changes drastically, but otherwise GetChunk()
158  // is size-oblivious.
159  if( mRecordSize < pOther.mRecordSize )
160  {
161  mRecordPoolSize = 0;
162  }
163 
164  mRecordSize = pOther.mRecordSize;
165  }
166  return(*this);
167  }

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