-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
55 lines (41 loc) · 1.09 KB
/
main.cpp
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
/*
* main.cpp
*
* Created on: Apr 4, 2011
* Author: Mahmoud
*
* The main file where the library is tested
*/
#include "FileHeap.h"
#include <cstdlib>
#include <time.h>
#include "Helper.h"
#include <iostream>
char * random_generator(int size);
int main() {
FileHeap file_heap("DATA_1.dat");
FilePointer *small_pointer = file_heap.alloc(16);
FilePointer *big_pointer = file_heap.alloc(16 * 4);
char* small_data = random_generator(10);
file_heap.setValue(small_pointer, small_data, 10);
char* small_data_retrieved = file_heap.getValue(small_pointer);
cout << small_data_retrieved << endl;
char* big_data = random_generator(50);
file_heap.setValue(big_pointer, big_data, 50);
char* big_data_retrieved = file_heap.getValue(big_pointer);
cout << big_data_retrieved << endl;
delete [] small_data;
delete [] big_data;
file_heap.free(small_pointer);
delete small_pointer;
delete big_pointer;
return 0;
}
char * random_generator(int size) {
char * data = new char[size];
srand(time(NULL));
for (int i = 0; i < size; i++) {
data[i] = 'a' + (rand() % 26);
}
return data;
}