I'm writing some memory management code in C++, and at first I use char *ptr = new char[1024]
instead of void *malloc(unsigned int size)
to get a buffer, after this, there's no concept of array in my code, all the operation is done by pointers.
But when I want to free them, I got some worries. As far as I know, C++ asked programmers to use delete[]
when acquire memory by using new *type*[]
, but at this moment I only got a pointer (which is ptr
in the case above). Before coding this I think why using delete[]
is to call the destructors on each element. But I'm not sure if there's a difference between delete
and delete[]
on a pod array.
So is it safe to use delete ptr
on a pod array?