Is the magic of placement new?

I play with dynamic memory allocation “manually”, and I wanted to see how the repository will be implemented by the guys from MS, but when debugging it “intervened” it moved me to the code:

inline void *__CRTDECL operator new(size_t, void *_Where) _THROW0()
{   // construct array with placement at _Where
return (_Where);
}

Can someone explain to me how on earth this code puts my object in the place indicated by my pointer when all I see in this code is a line with a return statement with what I set as an argument. I don’t think that saying in a comment that I would like this fnc to do is actually enough for it to work. Thank you for your constructive answers.

+3
source share
2 answers

operator new , . , , , " , , ". , operator new, new. operator new , .

+14

, , new T(...) ( " " ), - : . , . operator new. , , operator new , .

- . , this. , , : no-op, .

inline void* operator new(size_t, void *p) throw()
{
  return p;
}

- no-op.

+5

Source: https://habr.com/ru/post/1722817/


All Articles