Standard placement operator
Norman Feske
norman.feske at ...1...
Wed Mar 20 08:46:32 CET 2013
Hello Daniel,
> [...] how do I use the std c++ new placement
> operator which take void *, i.e.
>
> void * p = ::malloc(256);
> T * obj = new (p) T();
>
> When I try to use this it cannot find the operator, only the Genode
> allocator version. I have 'cxx' in my target.mk
in the rare cases where the Genode base system needs a placement new
operator, we host it in the implementation file. For example,
'base/src/base/allocator/slab.cc' contains one. This way, the operator
is defined only if really intended, which avoids using it by accident.
It is a single line of code:
inline void *operator new(size_t, void *at) { return at; }
Alternatively, if you are using the standard C++ library anyway, you may
use the definition provided by libsupc++. Just specify your LIBS
declaration in your 'target.mk' file as follows:
LIBS = libc libm stdcxx
Now, you can just '#include <new>' and use the placement new operator
provided there.
Cheers
Norman
--
Dr.-Ing. Norman Feske
Genode Labs
http://www.genode-labs.com · http://genode.org
Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth
More information about the users
mailing list