-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.cpp
More file actions
executable file
·55 lines (48 loc) · 1.45 KB
/
memory.cpp
File metadata and controls
executable file
·55 lines (48 loc) · 1.45 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
/* ---------------------------------------------------------------------------
** Ilinois Institute of Technology
** Memory cpp File
** Author: Igor Lopes
** September 21st, 2015
** -------------------------------------------------------------------------*/
#include <ctime> //ctime function used with Random.
#include <cstdlib> //Random function.
//------------------Header--------------------------------------------------
#include "memory.h"
using namespace std;
int Memory::getSize(){ return rand() % maxSize + minSize; }
char Memory::getChar(){
const char alphabet[]=
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
int lenght = sizeof (alphabet) - 1;
return alphabet[rand() % lenght];
}
void Memory::allocDynamic(){
int size = getSize() * 1000;
char *pchar;
pchar = (char*) malloc (size);
for(int i = 0; i < size; i++){
pchar[i] = getChar();
}
cout << "Memory Allocated: " << size << "bytes" << endl;
}
void Memory::allocStatic(){
int size = staticSize * 1000;
char *pchar;
pchar = (char*) malloc (size);
for(int i = 0; i < size; i++){
pchar[i] = getChar();
}
cout << "Memory Allocated: " << size << "bytes" << endl;
}
void Memory::debugValues(){ //Print the values of the variables passed to this class.
cout <<"Min Size:"<< minSize <<endl;
cout <<"Max Size:"<< maxSize <<endl;
cout <<"Static Size:"<< staticSize <<endl;
if(isStatic){
cout << "Static: true" <<endl;
} else {
cout << "Static: false" <<endl;
}
}