#include "mem.h" #include #include #include typedef struct frame { int no; int page; int r; /* bit pour la seconde chance */ } frame ; typedef struct fifo { int head; int tail; int nbelem; } fifo; typedef struct mem { int nbframes; frame * frames; } mem; static mem * memory=NULL; static fifo FIFO; /* Fifo est buffer circulaire * head pointe sur la tete (element le plus ancien) * tail pointe sur la queue (element le plus recent) * nbelem represente le nombre d'element dans la file * head et tail progressent modulo le nombre de frame * dans la memoire */ /* * Memoire ------------- | frame 0 | <- head ------------- | frame 1 | ------------- | frame 2 | ------------- | frame 3 | ------------- | frame 4 | ------------- | ... | ------------- | ... | ------------- | ... | <- tail ------------- | ... | ------------- */ static int init(int n) { int i; memory = (mem*)calloc(1,sizeof(mem)); memory-> nbframes = n; memory-> frames = (frame *) calloc(n,sizeof(frame)); if (memory -> frames == NULL) return -1; for(i=0;iframes[i].no = i; memory->frames[i].page = -1; /* les frames sont vides initialement */ memory->frames[i].r=0; } FIFO.head = FIFO.tail = 0; FIFO.nbelem = 0; return n; } static int _page_is_in(int page) { /* a ecrire */ } static int _fifo_is_full() { return (FIFO.nbelem == memory->nbframes); } int get_page_2chance(int page) { /* pour la deuxieme question */ } int get_page_fifo(int page) { /* a ecrire */ } void simu(int nb_frame,int t[],int l) { int i,j; init(nb_frame); frame ** trace; trace = (frame **) malloc(sizeof(frame *) * l); int * defaut = (int *) calloc(l,sizeof(int)); for (i=0;iframes,sizeof(frame)*nb_frame); } printf("------------"); for (i=0;iframes); free(memory); memory = NULL; for(i=0;i