CSEngine
Loading...
Searching...
No Matches
MemoryMgr.cpp
1#include<algorithm>
2#include "MemoryMgr.h"
3
4#ifdef _WIN32
5
6#include <windows.h>
7
8#ifdef _DEBUG
9#include <typeinfo>
10
11#endif
12#elif __ANDROID__
13
14#define LOGE(...) __android_log_print(ANDROID_LOG_DEBUG,"SCEngineMomory",__VA_ARGS__)
15#include <android/log.h>
16
17#elif __linux__
18
19#include <iostream>
20#include <typeinfo>
21
22#endif
23
24using namespace CSE;
25
26MemoryMgr::MemoryMgr() = default;
27
28MemoryMgr::~MemoryMgr() = default;
29
30
31void MemoryMgr::ExterminateObjects(bool killAll) {
32
33 auto iter = m_objects.begin();
34 while (iter != m_objects.end()) {
35 auto object = *iter;
36 if (object == nullptr) {
37 ++iter;
38 continue;
39 }
40
41#ifdef _DEBUG
42 OutputDebugStringA("Auto Releasing Object : ");
43 OutputDebugStringA(typeid(*object).name());
44 OutputDebugStringA("...\n");
45#elif __ANDROID__
46 LOGE("Auto Releasing Object : UNKOWN...");
47#elif __linux__
48 std::cout << "Auto Releasing Object : " << typeid(*object).name() << "...\n";
49#endif
50 if (object->isUndestroyable && !killAll) {
51#ifdef WIN32
52 OutputDebugStringA("denied.\n");
53#elif __ANDROID__
54 LOGE("denied.\n");
55#endif
56 ++iter;
57 continue;
58 }
59
60 object->Exterminate();
61 iter = m_objects.erase(iter);
62 m_hashContainer.erase(object->GetHash());
63 SAFE_DELETE(object);
64#ifdef WIN32
65 OutputDebugStringA("deleted.\n");
66#elif __ANDROID__
67 LOGE("deleted.\n");
68#elif __linux__
69 std::cout << "deleted.\n";
70#endif
71 }
72
73 m_objects.erase(std::remove(m_objects.begin(), m_objects.end(), nullptr), m_objects.end());
74}
75
76
77void MemoryMgr::ReleaseObject(SObject* object, bool isForce) {
78 if (object == nullptr) return;
79
80 if (object->isUndestroyable && !isForce) {
81#ifdef WIN32
82 OutputDebugStringA("Releasing Object is denied.");
83#elif __ANDROID__
84 LOGE("Releasing Object is denied.");
85#endif
86 return;
87 }
88
89 auto iObj = std::find(m_objects.begin(), m_objects.end(), object);
90
91 if (iObj != m_objects.end()) {
92#ifdef _DEBUG
93 OutputDebugStringA("Releasing Object : ");
94 OutputDebugStringA(typeid(*object).name());
95 OutputDebugStringA("...\n");
96#elif __ANDROID__
97 LOGE("Releasing Object : UNKOWN...");
98#endif
99 object->Exterminate();
100 Remove(object);
101 SAFE_DELETE(object);
102
103#ifdef WIN32
104 OutputDebugStringA("deleted\n");
105#elif __ANDROID__
106 LOGE("deleted\n");
107#endif
108 }
109}
110
111void MemoryMgr::Init() {
112
113}