-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (39 loc) · 1.12 KB
/
main.cpp
File metadata and controls
61 lines (39 loc) · 1.12 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include "Factories/AbstractFactory.h"
#include "Factories/SDLFactory.h"
#include "Controllers/Headers/Game.h"
struct AllocationMetrics{
uint32_t TotalAllocated =0;
uint32_t TotalFreed =0;
uint32_t CurrentUsage(){return TotalAllocated-TotalFreed;}
};
static AllocationMetrics s_AllocationMetrics;
static void PrintMemoryUsage()
{
std::cout << "Memory usage: " << s_AllocationMetrics.CurrentUsage() << " bytes" << std::endl;
}
void* operator new(size_t size)
{
s_AllocationMetrics.TotalAllocated += size;
PrintMemoryUsage();
return malloc(size);
}
void operator delete(void* memory,size_t size)
{
s_AllocationMetrics.TotalFreed += size;
PrintMemoryUsage();
free(memory);
}
int main(int argc, char *argv[]) {
//create SDL factory
GameNs::AbstractFactory *AF = new SDLNs::SDLFactory();
//initialise game class
GameNs::Game *g = GameNs::Game::getInstance(AF);
//run game
g->run();
//Deallocate memory
delete g;
delete AF;
std::cout << "Memory at the end of game: " << s_AllocationMetrics.CurrentUsage() << std::endl;
return 0;
}