mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-21 00:23:16 +00:00
base: Add 'construct_at' utility
This utility allows for the manual placement of objects without the need to have a global placement new operation nor the need for type-specific new operators. Issue #989
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#ifndef _INCLUDE__UTIL__VOLATILE_OBJECT_H_
|
||||
#define _INCLUDE__UTIL__VOLATILE_OBJECT_H_
|
||||
|
||||
#include <util/construct_at.h>
|
||||
#include <base/printf.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
@ -39,21 +40,6 @@ class Genode::Volatile_object
|
||||
{
|
||||
private:
|
||||
|
||||
/**
|
||||
* Utility to equip an existing type 'T' with a placement new operator
|
||||
*/
|
||||
template <typename T>
|
||||
struct Placeable : T
|
||||
{
|
||||
template <typename... ARGS>
|
||||
Placeable(ARGS &&... args)
|
||||
:
|
||||
T(args...)
|
||||
{ }
|
||||
|
||||
void *operator new (size_t, void *ptr) { return ptr; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Static reservation of memory for the embedded object
|
||||
*/
|
||||
@ -66,7 +52,7 @@ class Genode::Volatile_object
|
||||
|
||||
template <typename... ARGS> void _do_construct(ARGS &&... args)
|
||||
{
|
||||
new (_space) Placeable<MT>(args...);
|
||||
construct_at<MT>(_space, args...);
|
||||
_constructed = true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user