Standard placement operator

Daniel Waddington daniel.waddington at ...161...
Wed Mar 20 16:55:17 CET 2013


Ahh, thanks Norman, it was the combination of LIBS += stdcxx and 
#include <new> that I was looking for.

Daniel

On 03/20/2013 12:46 AM, Norman Feske wrote:
> 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
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.genode.org/pipermail/users/attachments/20130320/faa715cc/attachment.html>


More information about the users mailing list