alloc/arena: Add an arena that contains an allocator.

This commit is contained in:
Danny Robson 2018-10-01 15:35:06 +10:00
parent 6b1dbb3834
commit 6dede936bd

View File

@ -79,6 +79,43 @@ namespace cruft::alloc {
private: private:
T &m_store; T &m_store;
}; };
}
/// A simple allocator that contains a raw allocator and a forwarded
/// allocator.
///
/// The raw allocator handles the memory allocation, the forwarded
/// allocator performs the initialisation, and we control the construction
/// of both.
///
/// Ideally we wouldn't forward calls manually and instead do something
/// like inherit from arena<T>, but that makes it difficult to initialise
/// the raw allocator before we have to supply the reference to the arena.
template <typename AllocT>
class owned {
public:
template <typename ...ArgsT>
owned (ArgsT &&...args):
m_store (std::forward<ArgsT> (args)...),
m_arena {m_store}
{ ; }
template <typename T, typename ...ArgsT>
decltype(auto) acquire (ArgsT &&...args)
{ return m_arena.template acquire<T,ArgsT...> (std::forward<ArgsT> (args)...); }
template <typename ...ArgsT>
decltype(auto) release (ArgsT &&...args)
{ return m_arena.release (std::forward<ArgsT> (args)...); }
template <typename T, typename ...ArgsT>
decltype(auto) unique (ArgsT &&...args)
{ return m_arena.template unique<T,ArgsT...> (std::forward<ArgsT> (args)...); }
private:
AllocT m_store;
arena<AllocT> m_arena;
};
};
#endif #endif