class Foo{
//some member
public:
int bar;
}
int main(){
char* buffer = new char[100];
Foo* f = new(buffer)Foo();
//do i have to
delete f;
//or is
delete[] buffer;
//enough
}
Sure i have to delete it if the delete of Foo
has some major effect on the system but lets say it is a simple storage object which i place which is compleatly inside of the buffer and has no deconstructor which does delete some other things.
- Do i have to delete a object which where places with the new inside of a buffer or is it enough to delete the buffer?
- If i have to call delete on every object inside of the buffer, why do i have todo this?
I read: what-uses-are-there-for-placement-new and he also says
You should not deallocate every object that is using the memory buffer. Instead you should delete[] only the original buffer.