The new
operator is almost the same as a malloc
call, except that it invokes a constructor call on the object created immediately after the memory is allocated. Objects allocated with the operator new
should be deallocated with the operator delete
(and not free()
).
In C++, use of
malloc()
was replaced, as best practice, by use of the operator new
. The main difference between the functionality of malloc()
and the operator new
is that new
will call the constructor on object types after memory allocation.
|
|
---|---|
Allocates a zone of contiguous space for use. |
Allocates a zone of contiguous space for use. Calls constructor as object type used as an argument to the operator |