-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.h
executable file
·56 lines (37 loc) · 1.41 KB
/
memory.h
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
#ifndef __MEMORY_H_
#define __MEMORY_H_
#include "code_object.h"
class eNoLongerAllocated
{
public:
eNoLongerAllocated();
virtual ~eNoLongerAllocated();
const char * GetReason() const { return "Unit of memory is no longer allocated."; }
};
class MemoryManager : iCodeObject
{
protected:
short memReferences;
short memAllocations;
bool DeleteReference(); // decrease reference count by one, and return true if ref = 0
bool DeleteMemory(); // decrease reference/allocation count by one, return true if ref = 0
public:
MemoryManager();
virtual ~MemoryManager();
MemoryManager * memoryCreateReference(); // increase reference count by one
MemoryManager * memoryCreateAllocation(); // increase reference + allocation by one
bool memoryIsAllocated();
short memoryGetReferences() { return memReferences; }
short memoryGetAllocations() { return memAllocations; }
friend void DeleteMemoryAllocation(MemoryManager * memory);
friend void DeleteMemoryReference(MemoryManager * memory);
////////////////////////
// Code object interface
////////////////////////
virtual const string codeGetClassName(); // Return the name of the class.
virtual const string codeGetBasicInfo(); // Return a short summary of the object.
virtual const string codeGetFullInfo(); // Return a complete summary of the object.
};
void DeleteMemoryAllocation(MemoryManager * memory);
void DeleteMemoryReference(MemoryManager * memory);
#endif