Possible Duplicate:
delete[] supplied a modified new-ed pointer. Undefined Behaviour?
Let’s say I’ve allocated a handful of characters using new char[number].
Will it be possible to delete only a few end characters (something like delete[] (charArray + 4);, which will supposedly de-allocate all of characters except for the first four)?
I read that some implementations’ new[] store the number of objects allocated before the array of objects so that delete[] knows how many objects to de-allocate, so it’s probably unsafe to do what I’m asking…
Thanks.
EDIT:
Is manually deleting the unwanted end bytes using separate delete statements a safe way to do what I’m asking?
The only “safe” way to do it is to allocate a new array, copy the data, and delete the old one. Or you could just follow the
std::vectorway and differentiate between “capacity” (the size of the array) and “size” (the amount of elements in it).