Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*===========================================================================*
- * alloc_worst_fit *
- *===========================================================================*/
- PRIVATE phys_clicks alloc_worst_fit(clicks)
- phys_clicks clicks;
- {
- register struct hole *hp, *prev_ptr, *max_hole;
- phys_clicks old_base;
- do
- {
- hp = hole_head; /* initiate hp pointer */
- max_hole = hole_head; /* set hole_head as max_hole (will be updated) */
- while(hp != NIL_HOLE && hp->h_base < swap_base)
- {
- if(hp->h_len >= clicks && hp->h_len > max_hole->h_len)
- {
- /* We found a hole that is bigger than the last one. */
- max_hole = hp;
- }
- prev_ptr = hp;
- hp = hp->h_next;
- } /* while */
- /* check whether this block is big enough */
- if(max_hole->h_len >= clicks)
- {
- old_base = max_hole->h_base; /* remember where it started */
- max_hole->h_base += clicks; /* bite a piece off */
- max_hole->h_len -= clicks; /* ditto */
- /* Delete the hole if used up completely. */
- if (max_hole->h_len == 0)
- del_slot(prev_ptr, max_hole);
- /* Return the start address of the acquired block. */
- return(old_base);
- }
- } while (swap_out()); /* try to swap some other process out */
- return(NO_MEM)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement