Syntax
class Allocatable
{
public:
template <typename... Args> static Type *Allocate(Args &&...aArgs)
{
void *buf = Heap::CAlloc(1, sizeof(Type));
return (buf != nullptr) ? new (buf) Type(static_cast<Args &&>(aArgs)...) : nullptr;
}
template <typename... Args> static Type *AllocateAndInit(Args &&...aArgs)
{
void *buf = Heap::CAlloc(1, sizeof(Type));
Type *object = nullptr;
VerifyOrExit(buf != nullptr);
object = new (buf) Type();
if (object->Init(static_cast<Args &&>(aArgs)...) != kErrorNone)
{
object->Free();
object = nullptr;
}
exit:
return object;
}
void Free(void)
{
static_cast<Type *>(this)->~Type();
Heap::Free(this);
}
protected:
Allocatable(void) = default;
};