Last active
December 15, 2015 14:59
-
-
Save monolithed/5278286 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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