-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.c
86 lines (74 loc) · 2.05 KB
/
demo.c
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
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include "linkedList.h"
#include "main_1.h"
int main()
{
if ( Mem_Init(100) ) //process requests for 1000 bytes
{
printf("\nMem_Init successful\n");
}
else
{
printf("\nMem_Init failed\n");
return 1;
}
void *a = Mem_Alloc(30);
void *f = Mem_Alloc(10);
void *b = Mem_Alloc(30);
void *c = Mem_Alloc(10);
void *w = Mem_Alloc(30);
printf("\n\t Total allocated memory : %d and total allotted : %d unused : %d ",allocated,allotted,allotted - allocated);
traverse(head);
printf("\n");
int ret = Mem_Free(c);
if (ret == 0 )
printf("\n Memory Freed successfully ");
else if(ret == 1)
printf("\n No operation occurred ");
else
printf("\n Memory is already free ");
traverse(head);
printf("\n");
ret = Mem_Free(b);
if (ret == 0 )
printf("\n Memory Freed successfully ");
else if(ret == 1)
printf("\n No operation occurred ");
else
printf("\n Memory is already free ");
traverse(head);
printf("\n");
void *d = Mem_Alloc(40);
traverse(head);
ret = Mem_Free(a);
if (ret == 0 )
printf("\n Memory Freed successfully ");
else if(ret == 1)
printf("\n No operation occurred ");
else
printf("\n Memory is already free ");
printf("\n\t Total allocated memory : %d and total allotted : %d unused : %d ",allocated,allotted,allotted - allocated);
traverse(head);
traverse(head1);
printf("\n");
void *s = Mem_Check();
traverse(head);
traverse(head1);
int valid = Mem_IsValid(f+200);
if( valid == 1 )
printf("\n\t Memory is valid ");
else
printf("\n\t Memory is invalid ");
int k=Mem_Free(f+198);
printf("Freed");
void *g;
int size = Mem_GetSize(g);
if(size == -1)
printf("\n Not a valid memory ");
else
printf("\n Size is : %d ",size);
traverse(head1);
}