-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cpp
More file actions
36 lines (29 loc) · 772 Bytes
/
Example.cpp
File metadata and controls
36 lines (29 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "SimpleAllocator.hpp"
class A {
public:
~A() {
std::cout << "Destroying instance of A\n";
}
};
int main() {
{
alloc::SmartSimpleAllocator<A> smartStringAllocator;
alloc::SmartSimpleAllocator<A>::unique_t unique = smartStringAllocator.allocate();
auto ptr = smartStringAllocator.allocate();
{
auto ptr2 = smartStringAllocator.allocate();
auto ptr3 = smartStringAllocator.allocateShared();
}
}
{
alloc::SimpleAllocator<std::string> stringAllocator;
std::vector<std::string*> strings;
for (int i = 0; i < 10; ++i) {
strings.push_back(stringAllocator.allocate(std::to_string(i)));
}
stringAllocator.deallocate(strings.back());
strings.pop_back();
std::string* s = stringAllocator.allocate();
(void)s; //THIS LEAKS
}
}