Memory Aloocation with Pages


/*Program For Memory Aloocation with Pages*/

#include<iostream.h>

#include<conio.h>

void main()

{

int npage,pgsz,nframe,phmsz,lgmsz,i,j,k;

int frmpos[10],ptable[10];

char lgmdata[20],phmdata[20];

clrscr();

cout<<“Memory allocation with pages\n”;

cout<<“Enter the physical memory size:\n”;

cin>>phmsz;

cout<<“How many pages you want:”;

cin>>npage;

cout<<“Enter your page size:”;

cin>>pgsz;

lgmsz=npage*pgsz;

cout<<“Enter the logical address”;

for(i=0;i<phmsz;i++)

cin>>lgmdata[i];

for(i=0;i<lgmsz;lgmdata[i++]);

nframe=phmsz/pgsz;

cout<<“Select the frames to store pages between 0 to”<<nframe-1<<endl;

for(i=0;i<npage;++i)

{

cout<<“Enter the frame no. to store page”<<i<<“:”;

cin>>ptable[i];

}

for(i=0;i<npage;++i)

frmpos[i]=ptable[i]*pgsz;

for(i=0;i<phmsz;phmdata[i++]=’ ‘);

for(k=i=0;i<npage;++i)

for(j=frmpos[i];j<frmpos[i]+pgsz;++j,++k)

phmdata[j]=lgmdata[k];

cout<<“Data stored in pysical memory:”;

for(i=0;i<phmsz;++i)

cout<<” “<<i<<“-“<<phmdata[i]<<endl;

getch();

}

Advertisements