Skip to content

Commit 1d3caf5

Browse files
authored
prog5 added
1 parent 826b724 commit 1d3caf5

File tree

6 files changed

+700
-0
lines changed

6 files changed

+700
-0
lines changed

User defined malloc and free/a.out

17.3 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a.out: weightb.o
2+
gcc weightb.o
3+
4+
weightb.o: weightb.c weigth.h
5+
gcc -c weightb.c
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User defined malloc and free has been implemented using Weighted Buddy
2+
Method for Dynamic Storage Allocation.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "weigth.h"
4+
5+
void initialize();
6+
7+
int main(){
8+
printf("%d",ispow(24));
9+
initialize();
10+
print("\n");
11+
}
12+
13+
void initialize(){
14+
mem=(void*)malloc(sizeof(msize));
15+
printf("%p %ld",mem,sizeof(mem));
16+
//printf("\n%d",(int)mem*2);
17+
avail fd;
18+
init(&fd);
19+
20+
//void* c=(void*)bmalloc(&fd,5);
21+
char* c=(char*)bmalloc(&fd,sizeof(char));
22+
printf("\nValue = %p",c);
23+
printdat(&fd);
24+
25+
//void* fin=(void*)bmalloc(&fd,3);
26+
//printf(" %d",reqsize(1));
27+
//printf(" %d",bsizearr(2));
28+
int* x=(int*)bmalloc(&fd,sizeof(int));
29+
printf("\nValue = %p %ld",x,sizeof(int));
30+
printdat(&fd);
31+
//printf("\n%d",sizeof(char));
32+
bfree(&fd,c);
33+
printdat(&fd);
34+
bfree(&fd,x);
35+
printdat(&fd);
36+
37+
char* d=(char*)bmalloc(&fd,sizeof(char));
38+
printdat(&fd);
39+
/*bmalloc(&fd,8);
40+
41+
42+
bmalloc(&fd,3);
43+
float* x1=(float*)bmalloc(&fd,sizeof(float));
44+
if(x1!=NULL)
45+
*x1=2.654;
46+
printf("\nValue = %f ",*x1);
47+
bfree(&fd,x1);
48+
//printf("\n%d",ispow(3));
49+
//printf("%d",splitter(32,2));
50+
*/
51+
free(mem);
52+
}
14.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)