FBX C++ API Reference
FbxHungryAllocator Class Reference

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

#include <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)
 

Detailed 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 87 of file fbxcontainerallocators.h.

Constructor & Destructor Documentation

FbxHungryAllocator ( size_t  pRecordSize)
inline

Definition at line 90 of file fbxcontainerallocators.h.

90  :
91  mRecordSize(pRecordSize),
92  mRecordPoolSize(0),
93  mData(NULL)
94  {
95  }
#define NULL
Definition: fbxarch.h:213
FbxHungryAllocator ( const FbxHungryAllocator pOther)
inline

Definition at line 97 of file fbxcontainerallocators.h.

97  :
98  mRecordSize(pOther.mRecordSize),
99  mRecordPoolSize(pOther.mRecordPoolSize),
100  mData(NULL)
101  {
102  }
#define NULL
Definition: fbxarch.h:213
~FbxHungryAllocator ( )
inline

Definition at line 104 of file fbxcontainerallocators.h.

105  {
106  MemoryBlock* lCurrent = mData;
107  MemoryBlock* lNext = lCurrent ? lCurrent->mNextBlock : 0;
108  while (lCurrent)
109  {
110  FbxDelete(lCurrent);
111  lCurrent = lNext;
112  lNext = lCurrent ? lCurrent->mNextBlock : 0;
113  }
114  }
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 116 of file fbxcontainerallocators.h.

117  {
118  MemoryBlock* lMem = FbxNew< MemoryBlock >(pRecordCount* mRecordSize);
119  lMem->mNextBlock = mData;
120  mData = lMem;
121  mRecordPoolSize += pRecordCount;
122  }
void* AllocateRecords ( const size_t  pRecordCount = 1)
inline

Definition at line 124 of file fbxcontainerallocators.h.

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

Definition at line 147 of file fbxcontainerallocators.h.

148  {
149  // "Hungry": release memory only when the allocator is destroyed.
150  }
size_t GetRecordSize ( ) const
inline

Definition at line 152 of file fbxcontainerallocators.h.

153  {
154  return mRecordSize;
155  }
FbxHungryAllocator& operator= ( const FbxHungryAllocator pOther)
inline

Definition at line 157 of file fbxcontainerallocators.h.

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

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