c++ - Peculiar way for object creation? -


here example of implementing class creating objects:

template <class t> struct malloccreator {     static t* create() {         void* buf = std::malloc(sizeof(t));         if (!buf) return 0;         return new(buf) t;     } }; 

by using malloc , new operator.

what role of new , above syntax?

it's "placement new". code create raw memory size of 1 t malloc , construct new t in raw memory.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

dataset - MPAndroidchart returning no chart Data available -

post - imageshack API cURL -