Skip to content

Instantly share code, notes, and snippets.

@monolithed
Last active December 15, 2015 14:59
Show Gist options
  • Save monolithed/5278286 to your computer and use it in GitHub Desktop.
Save monolithed/5278286 to your computer and use it in GitHub Desktop.
class A {
public:
A(int x) {};
~A() {};
};
const int n = 10;
A* placement_memory = static_cast<A*>(operator new[] (n * sizeof(A)));
for (int i = 0; i < n; i++) {
new (placement_memory + i) A(rand()); // здесь память для объекта не выделяется, но инициализируется
}
// деинициализация памяти
while (i--) {
placement_memory[i].~A();
}
operator delete[] (placement_memory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment