Syntax
class Pool : private NonCopyable
{
public:
Pool(void)
: mFreeList()
{
for (Type &entry : mPool)
{
mFreeList.Push(entry);
}
}
explicit Pool(Instance &aInstance)
: mFreeList()
{
for (Type &entry : mPool)
{
entry.Init(aInstance);
mFreeList.Push(entry);
}
}
Type *Allocate(void) { return mFreeList.Pop(); }
void Free(Type &aEntry) { mFreeList.Push(aEntry); }
void FreeAll(void)
{
mFreeList.Clear();
for (Type &entry : mPool)
{
mFreeList.Push(entry);
}
}
uint16_t GetSize(void) const { return kPoolSize; }
bool IsPoolEntry(const Type &aObject) const { return (&mPool[0] <= &aObject) && (&aObject < GetArrayEnd(mPool)); }
uint16_t GetIndexOf(const Type &aEntry) const { return static_cast<uint16_t>(&aEntry - mPool); }
Type &GetEntryAt(uint16_t aIndex) { return mPool[aIndex]; }
const Type &GetEntryAt(uint16_t aIndex) const { return mPool[aIndex]; }
private:
LinkedList<Type> mFreeList;
Type mPool[kPoolSize];
};
![]()
template <class Type, uint16_t kPoolSize> class Pool : private NonCopyable
![]()
return