-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingletonAllocator.h
More file actions
41 lines (33 loc) · 938 Bytes
/
Copy pathSingletonAllocator.h
File metadata and controls
41 lines (33 loc) · 938 Bytes
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
#include <string>
#include "Allocator.h"
#include "FirstFit.h"
#include "BestFit.h"
#include "WorstFit.h"
#include "GlobalFlag.h"
using namespace std;
extern char flag;
class SingletonAllocator {
private:
//create single instance of allocator
static Allocator* allocator;
SingletonAllocator() = default;
public:
static Allocator* getAllocator() {
if(allocator == nullptr){
if(flag == 'F'){
void* p = malloc(sizeof(FirstFit));
allocator = new (p) FirstFit();
}
else if(flag == 'B'){
void* p = malloc(sizeof(BestFit));
allocator = new (p) BestFit();
}
else if(flag == 'W'){
void* p = malloc(sizeof(WorstFit));
allocator = new (p) WorstFit();
}
}
return allocator;
}
};
Allocator* SingletonAllocator::allocator = nullptr;