xo-alloc: streamlining DArena allocation: + construct_with() helper
This commit is contained in:
parent
f9cc86e4a5
commit
1ec9759f19
5 changed files with 53 additions and 42 deletions
|
|
@ -100,6 +100,13 @@ namespace xo {
|
|||
/** @ret iterator pointing to just after the last allocation in this arena **/
|
||||
DArenaIterator end() const noexcept;
|
||||
|
||||
/** @ret header for first allocation in this arena **/
|
||||
AllocHeader * begin_header() const noexcept;
|
||||
/** @ret location of header for next (not yet performed!)
|
||||
* allocation in this arena
|
||||
**/
|
||||
AllocHeader * end_header() const noexcept;
|
||||
|
||||
/** get header from allocated object address **/
|
||||
header_type * obj2hdr(void * obj) noexcept;
|
||||
|
||||
|
|
@ -208,6 +215,22 @@ namespace xo {
|
|||
///@}
|
||||
};
|
||||
|
||||
/** construct a @tparam T instance from arguments @p args
|
||||
* using memory obtained from arena @p ialloc
|
||||
**/
|
||||
template <typename T,
|
||||
typename... Args>
|
||||
static T *
|
||||
construct_with(DArena & ialloc, Args&&... args)
|
||||
{
|
||||
std::byte * mem = ialloc.alloc(sizeof(T));
|
||||
|
||||
if (mem)
|
||||
return new (mem) T(std::forward<Args>(args)...);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue