-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkyNet.cpp
63 lines (55 loc) · 1.65 KB
/
SkyNet.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
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mmemory.h"
int _free(VA blockAddress);
int _read(VA blockAddress, void* bufferAddress, size_t bufferSize);
void print();
void defrag(struct block* previousBlock);
int main(int argc, char* argv[])
{
VA firstVirtualBlock = (VA)malloc(sizeof(VA)),
secondVirtualBlock = (VA)malloc(sizeof(VA)),
thirdVirtualBlock = (VA)malloc(sizeof(VA)),
fourthVirtualBlock = (VA)malloc(sizeof(VA)),
fifthVirtualBlock = (VA)malloc(sizeof(VA));
void *firstVirtualBuffer = "Alpha",
*secondVirtualBuffer = "Bravo",
*thirdVirtualBuffer = "Charlie",
*fourthVirtualBuffer = "Delta",
*fifthVirtualBuffer = "Echo";
_init(5, 10);
_write(firstVirtualBlock, firstVirtualBuffer, strlen((char*)firstVirtualBuffer));
_write(secondVirtualBlock, secondVirtualBuffer, strlen((char*)secondVirtualBuffer));
_write(thirdVirtualBlock, thirdVirtualBuffer, strlen((char*)thirdVirtualBuffer));
_write(fourthVirtualBlock, fourthVirtualBuffer, strlen((char*)fourthVirtualBuffer));
_write(fifthVirtualBlock, fifthVirtualBuffer, strlen((char*)fifthVirtualBuffer));
print();
_write(thirdVirtualBlock, "Foxtrot", strlen("Foxtrot"));
print();
_free(thirdVirtualBlock);
print();
system("pause");
return 0;
}
void print()
{
struct block* cur;
size_t freeMemory = 0;
int i = 0;
char d[40];
cur = firstBlock;
while (cur != NULL)
{
for (i = 0; i < 40; i++)
d[i] = '\0';
_read(cur->virtualAddress, d, 20);
// puts(d);
printf("%s\n", d);
freeMemory += cur->size;
cur = cur->next;
}
freeMemory = amountOfBytes - freeMemory;
printf("EMPTY : %d \n", freeMemory);
printf("=========================================\n");
}