sahchas

segmentito 2 la venganza

Nov 1st, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. int search_free_memory(int limit) {
  2.  
  3.   int       base = 0;
  4.   int       seg1_end;
  5.   segment_t seg1;
  6.   segment_t seg2;
  7.  
  8.   if( !list_size(segments) ){
  9.     return base;
  10.   }
  11.  
  12.   while( 1 ){
  13.  
  14.     seg1 = search_next_segment(-1);
  15.     seg2 = search_next_segment(seg1->base + seg1->limit);
  16.  
  17.     seg1_end = seg1->base + seg1->limit;
  18.  
  19.     if(!seg2){
  20.  
  21.       //No hay tiempo de pensar, usa el operador ternario
  22.       base =( tamanio - seg1_end >= limit? seg1_end: -1);
  23.  
  24.       break;
  25.     }
  26.  
  27.     if(seg2->base - seg1_end >= limit){
  28.       base = seg1_end;
  29.       break;
  30.     }
  31.  
  32.   }
  33.  
  34.   return base;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment