compiler construction - dynamically allocating a c++ object without using the new operator -
(c++/win32)
consider following call:
object obj = new object(a,b); other allocating virtual memory needed instance of object, else going on under hood there? compiler places explicit call constructor of object?
is there way initialize c++ object dynamically without use of keyword new?
if want initialize object in given memory zone, consider placement new (see this)
btw, ordinary object* n = new object(123) expression equivalent (see operator ::new)
void* p = malloc(sizeof(object)); if (!p) throw std::bad_alloc; object* n = new (p) object(123); // placement new @ p, // invokes constructor but implementation use non-malloc compatible allocator, don't mix new , free!
Comments
Post a Comment