2024-08-08 18:39:18 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class MyClass
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void* ptr;
|
|
|
|
|
|
|
|
MyClass()
|
|
|
|
{
|
2024-08-12 17:24:48 +00:00
|
|
|
std::cout << "Allocating 1MB\n";
|
|
|
|
|
|
|
|
// Allocate 1MB for no reason:
|
|
|
|
ptr = malloc(sizeof(1000 * 1000));
|
2024-08-08 18:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~MyClass()
|
|
|
|
{
|
|
|
|
free(ptr);
|
2024-08-12 17:24:48 +00:00
|
|
|
std::cout << "Destroyed 1MB\n";
|
2024-08-08 18:39:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MyClass myClass;
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2024-08-12 17:24:48 +00:00
|
|
|
// Trick question, how many times is it constructed and destroyed?
|
2024-08-08 18:39:18 +00:00
|
|
|
|
2024-08-12 17:24:48 +00:00
|
|
|
std::vector<MyClass> vecOfMyClasses;
|
|
|
|
vec.push_back(myClass);
|
|
|
|
vec.push_back(myClass);
|
2024-08-08 18:39:18 +00:00
|
|
|
}
|