forked from udacity/CppND-Garbage-Collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgc_details.h
More file actions
49 lines (45 loc) · 1.24 KB
/
gc_details.h
File metadata and controls
49 lines (45 loc) · 1.24 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
// This class defines an element that is stored
// in the garbage collection information list.
//
#ifndef DETAILS_H
#define DETAILS_H
template <class T>
class PtrDetails
{
public:
unsigned refcount; // current reference count
T *memPtr; // pointer to allocated memory
/* isArray is true if memPtr points
to an allocated array. It is false
otherwise. */
bool isArray; // true if pointing to array
/* If memPtr is pointing to an allocated
array, then arraySize contains its size */
unsigned arraySize; // size of array
// Here, mPtr points to the allocated memory.
// If this is an array, then size specifies
// the size of the array.
PtrDetails(T * ptr, unsigned size = 0)
{
// TODO: Implement PtrDetails
memPtr = ptr;
if(size > 0)
isArray = true;
else
isArray = false;
arraySize = size;
refcount = 1;
//end TODO
}
};
// Overloading operator== allows two class objects to be compared.
// This is needed by the STL list class.
template <class T>
bool operator==(const PtrDetails<T> &ob1,
const PtrDetails<T> &ob2)
{
// TODO: Implement operator==
return (ob1.memPtr == ob2.memPtr);
//end TODO
}
#endif