class Foo{
public:
int bar;
}
int main(){
char* buffer = new char[100];
Foo* f = new(buffer)Foo();
delete f;
delete[] buffer;
}
Of course, I need to delete it if the removal Foohas some significant impact on the system, but it can be said that this is a simple storage object that I place, which is completely inside the buffer, and does not have a deconstructor that removes some other things.
- Do I need to delete an object where there is space with a new one inside the buffer or is it enough to delete the buffer?
- If I need to call delete on every object inside the buffer, why do I have this?
I read: what-uses-are-there-for-placement-new and it also says
You do not have to free all objects that use the memory buffer. Instead, you should remove [] only the source buffer.