-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalTests.h
More file actions
98 lines (77 loc) · 2.38 KB
/
Copy pathGlobalTests.h
File metadata and controls
98 lines (77 loc) · 2.38 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Created by Fidelia Nawar on 2/13/20.
//
#ifndef INC_20S_3353_PA01_GLOBALTESTS_H
#define INC_20S_3353_PA01_GLOBALTESTS_H
#include <iostream>
#include <time.h>
#include "SingletonAllocator.h"
#include "Allocator.h"
#include "myAllocator.h"
#include "GlobalFlag.h"
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::bitset;
void* operator new(size_t val) {
//checking to see if word boundary is matched
int x = val % 8;
if(x == 0){
void* a = SingletonAllocator::getAllocator()->allocateMemory(val);
cout << "Overloading new at start address: " << a << endl;
return a;
}
else{
//changing to allocate memory up to the boundary
val = val - (val%8)+8;
void* a = SingletonAllocator::getAllocator()->allocateMemory(val);
cout << "Overloading new at start address: " << a << endl;
return a;
}
}
//overloaded new operator with a value
void* operator new(size_t val, int x) {
void* a = SingletonAllocator::getAllocator()->allocateWithVal(val, x);
cout << a << endl;
return a;
}
void* operator new[](size_t val){
int x = val % 8;
if(x == 0){
void* a = SingletonAllocator::getAllocator()->allocateMemory(val);
cout << "Overloading new[] at start address: " << a << endl;
return a;
}
else{
val = val - (val%8)+8;
void* a = SingletonAllocator::getAllocator()->allocateMemory(val);
cout << "Overloading new[] at start address: " << a << endl;
return a;
}
}
void operator delete(void* ptr) noexcept {
SingletonAllocator::getAllocator()->deallocateMemory(ptr);
}
void operator delete[](void* ptr) noexcept {
SingletonAllocator::getAllocator()->deallocateMemory(ptr);
}
void runSmallTest(){
cout << "----------------------------------------------------------------------------------" << endl;
cout << "SMOL stress test" << endl;
int* ptrArray = new int[32];
delete[] ptrArray;
char* arr = new char[1000];
delete[] arr;
int* large = new int(2305293);
delete large;
cout << "----------------------------------------------------------------------------------" << endl;
}
void runMediumTest(){
// vector<int>* newVec = new vector<int>{10, 3, 5, 3562, 24590};
// delete newVec;
time_t t;
time(&t);
srand((unsigned int) t);
}
#endif //INC_20S_3353_PA01_GLOBALTESTS_H