next up previous contents index
Next: delete operator Up: C++ Object Instantiation Previous: C++ Object Instantiation

new operator

 

As described above, the new operator is just an interface to malloc() routine. However, there are more features in the operator.

The statement

          Object *array = new Object[size](parameters, ...);
allocates a memory block of sizeof(Object) * size bytes, and the constructor of the object is called for each instance. The size is stored at the extra bytes at the head of the memory block.

The statement

          Object *obj = new(place) Object(parameters, ...);
does not call the malloc() routine but places the object at the place which is a pointer to an appropriate memory block. This scheme is integral to the interface to the mapping of objects in the persistent storage.



Mori Tetsuya / t2y3141592@gmail.com