I know both functions accepts size_t
number. For malloc
that number is raw bytes and for the allocate
it is rahter n*sizeof(T)
of that type. So does allocate
call internally malloc
? Also, from cpp reference about allocate
:
Allocates n * sizeof(T) bytes of uninitialized storage by calling ::operator new(std::size_t)
It calls new
operator. But as far as I know, the new
operator not only allocates memory, but also initialize it with the constructor for the type, from In what cases do I use malloc and/or new?:
The new keyword is the C++ way of doing it, and it will ensure that your type will have its constructor called
But the reference claim it will return uninitialized, only allocated memory, just as malloc
does. So the question is also a little bit about new
, does it also initialize (by calling default constructor or value-initilize for primitive types) or not? And does allocate
calls malloc
by its implementation or how does it requests OS for block of raw memory/