As far as the respective language standards go, C offers dynamic memory allocation only through the malloc()
family, while in C++ the most common form of alloca
On Visual C++, stepping into a new
expression leads me to this snippet in new.cpp
:
#include
#include
_C_LIB_DECL
int __cdecl _callnewh(size_t size) _THROW1(_STD bad_alloc);
_END_C_LIB_DECL
void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc)
{ // try to allocate size bytes
void *p;
while ((p = malloc(size)) == 0)
if (_callnewh(size) == 0)
{ // report no memory
static const std::bad_alloc nomem;
_RAISE(nomem);
}
return (p);
}
So VC++'s new
also wraps the malloc()
call.