|

楼主 |
发表于 2004-5-25 21:12:55
|
显示全部楼层
我改完的我原来程序的一个子程序,现在随机数产生没有问题,但在调用我原来需要的函数时,还是会出现段错误.
程序如下:
[php]
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define INVALID -1
#define null 0
#define total_instruction 320
#define total_vp 32
#define clear_period 50
typedef struct{
int pn,pfn,counter,time;
}pl_type;
pl_type pl[total_vp];
struct pfc_struct{
int pn,pfn;
struct pfc_struct *next;
};
typedef struct pfc_struct pfc_type;
pfc_type pfc[total_vp],*freepf_head,*busypf_head,*busypf_tail;
int diseffect,a[total_instruction];
int page[total_instruction],offset[total_instruction];
void initialize();
void FIFO();
main()
{
int S,i,j;
srand(10*getpid());
S=(int) (319.0*rand()/(RAND_MAX+1.0));
printf("%d\n",S);
for(i=0;i<total_instruction;i+=4)
{
a=S;
a[i+1]=S+1;
a[i+2]=(int)(a*rand()/RAND_MAX);
a[i+3]=a[i+2]+1;
S=(int) ((318.0-a[i+2])*rand()/RAND_MAX)+a[i+2]+2;
}
for(i=0;i<32;i++)
{printf("a[%d]=%d\n",i,a);}
for(i=0;i<total_instruction;i++)
{
page=a/10;
offset=a%10;
}
void initialize();
for(i=0;i<32;i++){printf("page[%d]=%d\n",i,page);}
for(i=0;i<32;i++){printf("offest[%d]=%d\n",i,offset);}
for(i=4;i<=32;i++)
{
printf("%2d page frames",i);
FIFO(i);
printf("\n");
}
}
void FIFO(total_pf)
int total_pf;
{ int i,j;
pfc_type *p,*t;
initialize(total_pf);
busypf_head=busypf_tail=null;
for(i=0;i<total_instruction;i++)
{
if(pl[page].pfn==INVALID)
{
diseffect+=1;
if(freepf_head==null)
{
p=busypf_head->next;
freepf_head=busypf_head;
freepf_head->next=null;
busypf_head=p;
}
p=freepf_head->next;
freepf_head->next=null;
freepf_head->pn=page;
pl[page].pfn=freepf_head->pfn;
if(busypf_tail->next==null)
busypf_head=busypf_tail=freepf_head;
else
{
busypf_tail->next=freepf_head;
busypf_tail=freepf_head;
}
freepf_head=p;
}
}
printf("FIFO:%6.4f",1-(float)diseffect/320);
}
void initialize(total_pf)
int total_pf;
{
int i;
diseffect=0;
for(i=0;i<total_vp;i++)
{
pl.pn=i;
pl.pfn=INVALID;
pl.counter=0;
pl.time=-1;
}
for(i=1;i<total_pf;i++)
{pfc[i-1].next=&pfc;pfc[i-1].pfn=i-1;}
pfc[total_pf-1].next=null;pfc[total_pf-1].pfn=total_pf-1;
freepf_head=&pfc[0];
}
[/php] |
|