Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. /*===========================================================================*
  2.  *                            alloc_worst_fit                                *
  3.  *===========================================================================*/
  4. PRIVATE phys_clicks alloc_worst_fit(clicks)
  5. phys_clicks clicks;
  6. {
  7.     register struct hole *hp, *prev_ptr, *max_hole;
  8.     phys_clicks old_base;
  9.  
  10.     do
  11.     {
  12.         hp = hole_head;         /* initiate hp pointer */
  13.         max_hole = hole_head;   /* set hole_head as max_hole (will be updated) */
  14.         while(hp != NIL_HOLE && hp->h_base < swap_base)
  15.         {
  16.             if(hp->h_len >= clicks && hp->h_len > max_hole->h_len)
  17.             {
  18.                 /* We found a hole that is bigger than the last one. */
  19.                 max_hole = hp;
  20.             }
  21.  
  22.             prev_ptr = hp;
  23.             hp = hp->h_next;
  24.         } /* while */
  25.  
  26.         /* check whether this block is big enough */
  27.         if(max_hole->h_len >= clicks)
  28.         {
  29.             old_base = max_hole->h_base;  /* remember where it started */
  30.             max_hole->h_base += clicks;   /* bite a piece off */
  31.             max_hole->h_len -= clicks;    /* ditto */
  32.  
  33.             /* Delete the hole if used up completely. */
  34.             if (max_hole->h_len == 0)
  35.                 del_slot(prev_ptr, max_hole);
  36.  
  37.             /* Return the start address of the acquired block. */
  38.             return(old_base);
  39.         }
  40.  
  41.     } while (swap_out());     /* try to swap some other process out */
  42.  
  43.     return(NO_MEM)
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement