I am trying to implement my own std::vector
container, and I am using realloc()
to resize it, to prevent deletion and reallocation every time. With the following code:
buffer = new T[n]();
This would default initialize each element of the array, and allow me to start accessing them right away. However, since the standard specifies that the memory must be previously allocated by malloc(), calloc() or realloc()
to use realloc()
, I cannot use new
.
I know that calloc()
will zero-initialize the memory, but I am not sure if that will have the same behavior as new T[n]()
. What is the proper way to default-intialize with C style memory allocation?