Go to the documentation of this file.
27 #ifndef _AKBLOCKPOOL_H
28 #define _AKBLOCKPOOL_H
41 #define AK_DYNA_BLK_SCRUB_MEM
44 #ifdef AK_DYNA_BLK_STATS
45 #define STATS_ALLOC() Stats_Alloc()
46 #define STATS_NEWCHUNK() Stats_NewChunk()
47 #define STATS_FREE() Stats_Free()
48 #define STATS_DELCHUNK() Stats_DelChunk()
51 #define STATS_NEWCHUNK()
53 #define STATS_DELCHUNK()
56 #ifdef AK_DYNA_BLK_SCRUB_MEM
57 #define SCRUB_NEW_CHUNK() memset(&memory, 0xCC, sizeof(T)*uPoolChunkSize)
58 #define SCRUB_NEW_ALLOC(pItem) memset(pItem, 0xAA, sizeof(T))
59 #define SCRUB_FREE_BLOCK(pObj) memset(pObj, 0xDD, sizeof(T))
61 #define SCRUB_NEW_CHUNK()
62 #define SCRUB_NEW_ALLOC(pItem)
63 #define SCRUB_FREE_BLOCK(pObj)
66 template <
typename T, AkUInt32 uPoolChunkSize,
class TAlloc = ArrayPoolDefault>
69 enum { kChunkMemoryBytes =
sizeof(T)*uPoolChunkSize };
74 char padding[
sizeof(T) -
sizeof(FreeBlock*) ];
80 PoolChunk() : pNextLightItem(
NULL)
83 for(
AkUInt32 i=0; i<uPoolChunkSize; ++i )
85 FreeBlock* pBlk =
reinterpret_cast<FreeBlock*
>( &memory ) + i;
86 freeList.AddFirst(pBlk);
90 inline bool BelongsTo( FreeBlock* pMem )
const {
return (
AkUInt8*)pMem >= memory && (
AkUInt8*)pMem < (memory+kChunkMemoryBytes); }
91 inline bool AllFree()
const {
return freeList.Length() == uPoolChunkSize; }
92 inline bool AllAllocd()
const {
return freeList.IsEmpty(); }
94 AkUInt8 memory[ kChunkMemoryBytes ];
95 PoolChunk* pNextLightItem;
109 template<
typename A1>
117 template<
typename A1,
typename A2>
125 template<
typename A1,
typename A2,
typename A3>
126 T*
New(A1 a1, A2 a2, A3 a3)
133 template<
typename A1,
typename A2,
typename A3,
typename A4>
134 T*
New(A1 a1, A2 a2, A3 a3, A4 a4)
149 m_chunkList.
Transfer(in_src.m_chunkList);
151 #ifdef AK_DYNA_BLK_STATS
152 uPeakUsedBytes = in_src.uPeakUsedBytes;
153 uPeakAllocdBytes = in_src.uPeakAllocdBytes;
154 uCurrentAllocdBytes = in_src.uCurrentAllocdBytes;
155 uCurrentUsedBytes = in_src.uCurrentUsedBytes;
157 in_src.uPeakUsedBytes = 0;
158 in_src.uPeakAllocdBytes = 0;
159 in_src.uCurrentAllocdBytes = 0;
160 in_src.uCurrentUsedBytes = 0;
167 FreeBlock* pItem =
NULL;
168 PoolChunk* pChunk =
NULL;
170 pChunk = m_chunkList.
First();
171 while (pChunk !=
NULL && pChunk->AllAllocd())
172 pChunk = pChunk->pNextLightItem;
176 pChunk = (PoolChunk *) TAlloc::Alloc(
sizeof( PoolChunk ) );
185 pItem = pChunk->freeList.First();
187 pChunk->freeList.RemoveFirst();
192 return reinterpret_cast<T*
>(pItem);
199 FreeBlock* pItem =
reinterpret_cast<FreeBlock*
>(pObj);
201 PoolChunk* pPrevChunk =
NULL;
202 PoolChunk* pChunk = m_chunkList.
First();
203 while (pChunk !=
NULL && !pChunk->BelongsTo(pItem))
206 pChunk = pChunk->pNextLightItem;
210 pChunk->freeList.AddFirst(pItem);
213 if (pChunk->AllFree())
216 pChunk->~PoolChunk();
222 tChunkList m_chunkList;
224 #ifdef AK_DYNA_BLK_STATS
227 uCurrentUsedBytes +=
sizeof(T);
228 uPeakUsedBytes =
AkMax(uCurrentUsedBytes, uPeakUsedBytes);
230 void Stats_NewChunk()
232 uCurrentAllocdBytes +=
sizeof(PoolChunk);
233 uPeakAllocdBytes =
AkMax(uCurrentAllocdBytes, uPeakAllocdBytes);
237 uCurrentUsedBytes -=
sizeof(T);
239 void Stats_DelChunk()
241 uCurrentAllocdBytes -=
sizeof(PoolChunk);
AkForceInline T * First()
Get first element.
#define SCRUB_FREE_BLOCK(pObj)
#define AkPlacementNew(_memory)
AKSOUNDENGINE_API void Free(AkMemPoolId in_poolId, void *in_pMemAddress)
#define SCRUB_NEW_CHUNK()
uint8_t AkUInt8
Unsigned 8-bit integer.
void AddFirst(T *in_pItem)
Add element at the beginning of list.
#define AKASSERT(Condition)
void RemoveItem(T *in_pItem, T *in_pPrevItem)
Remove an element.
T * New(A1 a1, A2 a2, A3 a3, A4 a4)
T * New(A1 a1, A2 a2, A3 a3)
#define SCRUB_NEW_ALLOC(pItem)
uint32_t AkUInt32
Unsigned 32-bit integer.
void Transfer(AkDynaBlkPool< T, uPoolChunkSize, TAlloc > &in_src)
void Transfer(AkListBare< T, U_NEXTITEM, COUNT_POLICY, LAST_POLICY > &in_src)
Besoin d'aide ?
Des questions ? Des problèmes ? Besoin de plus d'informations ? Contactez-nous, nous pouvons vous aider !
Visitez notre page d'Aide
Décrivez-nous de votre projet. Nous sommes là pour vous aider.
Enregistrez votre projet et nous vous aiderons à démarrer sans aucune obligation !
Partir du bon pied avec Wwise