#pragma once
namespace snmalloc
{
template<typename SAlloc = Alloc>
struct ScopedAllocator
{
SAlloc* alloc;
ScopedAllocator()
{
alloc = AllocPool<typename SAlloc::Config>::acquire();
};
ScopedAllocator(const ScopedAllocator&) = delete;
ScopedAllocator(ScopedAllocator&&) = delete;
ScopedAllocator& operator=(const ScopedAllocator&) = delete;
ScopedAllocator& operator=(ScopedAllocator&&) = delete;
~ScopedAllocator()
{
if (alloc != nullptr)
{
alloc->flush();
AllocPool<typename SAlloc::Config>::release(alloc);
alloc = nullptr;
}
}
SAlloc* operator->()
{
return alloc;
}
};
template<typename SAlloc = Alloc>
inline ScopedAllocator<SAlloc> get_scoped_allocator()
{
return {};
}
}