Recreated most of the demo code from talk

This commit is contained in:
nothke
2024-08-12 19:24:48 +02:00
parent 0730b9f6c4
commit 2030301fdb
5 changed files with 309 additions and 102 deletions

View File

@@ -8,12 +8,16 @@ public:
MyClass()
{
ptr = malloc(sizeof(100000000));
std::cout << "Allocating 1MB\n";
// Allocate 1MB for no reason:
ptr = malloc(sizeof(1000 * 1000));
}
~MyClass()
{
free(ptr);
std::cout << "Destroyed 1MB\n";
}
};
@@ -21,7 +25,9 @@ MyClass myClass;
int main()
{
std::vector<MyClass> vec;
vec.push_back({});
// Trick question, how many times is it constructed and destroyed?
std::vector<MyClass> vecOfMyClasses;
vec.push_back(myClass);
vec.push_back(myClass);
}