Difference between global non-throwing ::operator new and std::malloc
The main differences, aside from syntax and free
vs. delete
, are
- you can portably replace
::operator new
; malloc
comes withrealloc
, for whichnew
has no equivalent;new
has the concept of anew_handler
, for which there is nomalloc
equivalent.
(Replacing malloc
opens up a can of worms. It can be done, but not portably, because it requires knowledge of the linker.)
There are two differences I can think of:
Which function you must use to deallocate the memory,
operator delete
vs.free()
.A C++ program can legally provide its own version of
::operator new
and that version is guaranteed to be called bynew
expressions. It's not possible to overridemalloc
with your own version.