Add to Favorites    Make Home Page 8879 Online  
 Language Categories  
 Our Services  

Home » C Home » C on Unix Home » BUDDY SYSTEM

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title BUDDY SYSTEM
Author M.JEBARAJ
Author Email jebadotcom [at] yahoo.co.in
Description
Category C » C on Unix
Hits 392503
Code Select and Copy the Code
Code : // BUDDY SYSTEM CODE #include<stdio.h> #include<conio.h> int tree[2050],i,j,k; void segmentalloc(int,int),makedivided(int),makefree(int),printing(int,int); int place(int),power(int,int); main() { int totsize,cho,req; clrscr(); for(i=0;i<80;i++) printf("%c",5); printf(" B U D D Y S Y S T E M R E Q U I R E M E N T S "); for(i=0;i<80;i++) printf("%c",5); printf(" * Enter the Size of the memory : "); scanf("%d",&totsize); clrscr(); while(1) { for(i=0;i<80;i++) printf("%c",5); printf(" B U D D Y S Y S T E M "); for(i=0;i<80;i++) printf("%c",5); printf(" * 1) Locate the process into the Memory "); printf(" * 2) Remove the process from Memory "); printf(" * 3) Tree structure for Memory allocation Map "); printf(" * 4) Exit "); for(i=0;i<80;i++) printf("%c",5); printf(" * Enter your choice : "); scanf("%d",&cho); switch(cho) { case 1: clrscr(); printf(" "); for(i=0;i<80;i++) printf("%c",5); printf(" "); printf(" M E M O R Y A L L O C A T I O N "); for(i=0;i<80;i++) printf("%c",5); printf(" * Enter the Process size : "); scanf("%d",&req); segmentalloc(totsize,req); break; case 2: clrscr(); printf(" "); for(i=0;i<80;i++) printf("%c",5); printf(" "); printf(" M E M O R Y D E A L L O C A T I O N "); for(i=0;i<80;i++) printf("%c",5); printf(" * Enter the process size : "); scanf("%d",&req); makefree(req); break; case 3: clrscr(); printf(" "); for(i=0;i<80;i++) printf("%c",5); printf(" M E M O R Y A L L O C A T I O N M A P "); for(i=0;i<80;i++) printf("%c",5); printf(" "); printing(totsize,0); printf(" "); for(i=0;i<80;i++) printf("%c",5); getch(); clrscr(); break; default: return; } } } void segmentalloc(int totsize,int request) { int flevel=0,size; size=totsize; if(request>totsize) { printf(" %c R E S U L T : ",2); printf(" * The system don't have enough free memory "); printf(" * Suggession : Go for VIRTUAL MEMORY "); getch(); return; } while(1) { if(request<size && request>(size/2)) break; else { size/=2; flevel++; } } for(i=power(2,flevel)-1;i<=(power(2,flevel+1)-2);i++) if(tree[i]==0 && place(i)) { tree[i]=request; makedivided(i); printf(" Result : Successful Allocation "); break; } if(i==power(2,flevel+1)-1) { printf(" %c Result : "); printf(" * The system don't have enough free memory "); printf(" * Suggession : Go for VIRTUAL Memory Mode "); } } void makedivided(int node) { while(node!=0) { node=node%2==0?(node-1)/2:node/2; tree[node]=1; } } int place(int node) { while(node!=0) { node=node%2==0?(node-1)/2:node/2; if(tree[node]>1) return 0; } return 1; } void makefree(int request) { int node=0; while(1) { if(tree[node]==request) break; else node++; } tree[node]=0; while(node!=0) { if(tree[node%2==0?node-1:node+1]==0 && tree[node]==0) { tree[node%2==0?(node-1)/2:node/2]=0; node=node%2==0?(node-1)/2:node/2; } else break; } } int power(int x,int y) { int z,ans; if(y==0) return 1; ans=x; for(z=1;z<y;z++) ans*=x; return ans; } void printing(int totsize,int node) { int permission=0,llimit,ulimit,tab; if(node==0) permission=1; else if(node%2==0) permission=tree[(node-1)/2]==1?1:0; else permission=tree[node/2]==1?1:0; if(permission) { llimit=ulimit=tab=0; while(1) { if(node>=llimit && node<=ulimit) break; else { tab++; printf(" "); llimit=ulimit+1; ulimit=2*ulimit+2; } } printf(" %d ",totsize/power(2,tab)); if(tree[node]>1) printf("---> Allocated %d ",tree[node]); else if(tree[node]==1) printf("---> Divided "); else printf("---> Free "); printing(totsize,2*node+1); printing(totsize,2*node+2); } }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=1077


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review