/*
 * delete_node: Remove a free block pointer from a segregated list. If
 *              necessary, adjust pointers in predecessor and successor blocks
 *              or reset the list head.
 */
static void delete_node(void *ptr) {
  //int list = 0;
  size_t size = GET_SIZE(HDRP(ptr));

  /* Select segregated list */
 /* while ((list < LISTS - 1) && (size > 1)) {
    size >>= 1;
    list++;
  }*/
 
  if (PRED(ptr) != NULL) {
    if (SUCC(ptr) != NULL) {
      SET_PTR(SUCC_PTR(PRED(ptr)), SUCC(ptr));
      SET_PTR(PRED_PTR(SUCC(ptr)), PRED(ptr));
    } else {
      SET_PTR(SUCC_PTR(PRED(ptr)), NULL);
     // free_lists[list] = PRED(ptr);
    }
  } else {
    //intptr_t header1 = header + SUCC(ptr);
    if (SUCC(ptr) != NULL) {
      SET_PTR(PRED_PTR(SUCC(ptr)), NULL);
      head = SUCC(ptr);
    } else {
      head = 0;
     // free_lists[list] = NULL;
    }
  }

  return;
}
示例#2
0
/*
* delete_node: Remove a free block pointer from a segregated list. If
* necessary, adjust pointers in predecessor and successor blocks
* or reset the list head.
*/
static void delete_node(void *ptr) {
int list = 0;
size_t size = GET_SIZE(HEAD(ptr));
/* Select segregated list */
while ((list < LISTS - 1) && (size > 1)) {
size >>= 1;
list++;
}
if (PRED(ptr) != NULL) {
if (SUCC(ptr) != NULL) {
SET_PTR(SUCC_PTR(PRED(ptr)), SUCC(ptr));
SET_PTR(PRED_PTR(SUCC(ptr)), PRED(ptr));
} else {
SET_PTR(SUCC_PTR(PRED(ptr)), NULL);
free_lists[list] = PRED(ptr);
}
} else {
if (SUCC(ptr) != NULL) {
SET_PTR(PRED_PTR(SUCC(ptr)), NULL);
} else {
free_lists[list] = NULL;
}
}
return;
}
示例#3
0
static void delete_node(void *bp)
{
  int listNum = 0;
  size_t size = GET_SIZE(HDRP(bp));
  
  while ((listNum < LISTS - 1) && (size > 1))
  {
	size >>= 1;
	listNum++;
  }
  
  if (PRED(bp) != NULL)
  {
	if (SUCC(bp) != NULL)
	{
	  STORE(SUCC_PTR(PRED(bp)), SUCC(bp));
	  STORE(PRED_PTR(SUCC(bp)), PRED(bp));
	}
	else
	{
	  STORE(SUCC_PTR(PRED(bp)), NULL);
	  *(seg_listp + listNum) = PRED(bp);
	}
  }
  else
  {
	if (SUCC(bp) != NULL)
	{
	  STORE(PRED_PTR(SUCC(bp)), NULL);
	}
	else
	{
	  *(seg_listp + listNum) = NULL;
	}
  }
  
  return;
  
}
示例#4
0
static void insert_node(void *bp, size_t size)
{
  int listNum = 0;
  void *sptr = bp;
  void *iptr = NULL;
  
  //select list
  while ((listNum < LISTS - 1) && (size > 1))
  {
	size >>= 1;
	listNum++;
  }
  
  sptr = *(seg_listp + listNum);
  
  while ((sptr != NULL) && (size > GET_SIZE(HDRP(sptr))))
  {
	iptr = sptr;
	sptr = PRED(sptr);
  }
  
  if (sptr != NULL)
  {
	if (iptr != NULL)
	{
	  STORE(PRED_PTR(bp), sptr);
	  STORE(SUCC_PTR(sptr), bp);
	  STORE(SUCC_PTR(bp), iptr);
	  STORE(PRED_PTR(iptr), bp);
	}
	else
	{
	  STORE(PRED_PTR(bp), sptr);
	  STORE(SUCC_PTR(sptr), bp);
	  STORE(SUCC_PTR(bp), NULL);
	}
  }
  else
  {
	if (iptr != NULL)
	{
	  STORE(PRED_PTR(bp), NULL);
	  STORE(SUCC_PTR(bp), iptr);
	  STORE(PRED_PTR(iptr), bp);
	}
	else
	{
	  STORE(PRED_PTR(bp), NULL);
	  STORE(SUCC_PTR(bp), NULL);
	  
	  *(seg_listp + listNum) = bp;
	  
	}
  }
  
  return;
  
}
示例#5
0
/*
 * insert_node - Insert a block pointer into a segregated list. Lists are
 *               segregated by byte size, with the n-th list spanning byte
 *               sizes 2^n to 2^(n+1)-1. Each individual list is sorted by
 *               pointer address in ascending order.
 */
static void insert_node(void *ptr, size_t size) {
  int list = 0;
  void *search_ptr = ptr;
  void *insert_ptr = NULL;

  /* Select segregated list */
  while ((list < LISTS - 1) && (size > 1)) {
    size >>= 1;
    list++;
  }

  /* Select location on list to insert pointer while keeping list
     organized by byte size in ascending order. */
  search_ptr = free_lists[list];
  while ((search_ptr != NULL) && (size > GET_SIZE(HEAD(search_ptr)))) {
    insert_ptr = search_ptr;
    search_ptr = PRED(search_ptr);
  }

  /* Set predecessor and successor */
  if (search_ptr != NULL) {
    if (insert_ptr != NULL) {
      SET_PTR(PRED_PTR(ptr), search_ptr);
      SET_PTR(SUCC_PTR(search_ptr), ptr);
      SET_PTR(SUCC_PTR(ptr), insert_ptr);
      SET_PTR(PRED_PTR(insert_ptr), ptr);
    } else {
      SET_PTR(PRED_PTR(ptr), search_ptr);
      SET_PTR(SUCC_PTR(search_ptr), ptr);
      SET_PTR(SUCC_PTR(ptr), NULL);

      /* Add block to appropriate list */
      free_lists[list] = ptr;
    }
  } else {
    if (insert_ptr != NULL) {
      SET_PTR(PRED_PTR(ptr), NULL);
      SET_PTR(SUCC_PTR(ptr), insert_ptr);
      SET_PTR(PRED_PTR(insert_ptr), ptr);
    } else {
      SET_PTR(PRED_PTR(ptr), NULL);
      SET_PTR(SUCC_PTR(ptr), NULL);

      /* Add block to appropriate list */
      free_lists[list] = ptr;
    }
  }

  return;
}
示例#6
0
static void insert_node(void *ptr, size_t size) {
    int list = 0;
    void *search_ptr = ptr;
    void *insert_ptr = NULL;
    
    // Select segregated list 
    while ((list < LISTLIMIT - 1) && (size > 1)) {
        size >>= 1;
        list++;
    }
    
    // Keep size ascending order and search
    search_ptr = segregated_free_lists[list];
    while ((search_ptr != NULL) && (size > GET_SIZE(HDRP(search_ptr)))) {
        insert_ptr = search_ptr;
        search_ptr = PRED(search_ptr);
    }
    
    // Set predecessor and successor 
    if (search_ptr != NULL) {
        if (insert_ptr != NULL) {
            SET_PTR(PRED_PTR(ptr), search_ptr);
            SET_PTR(SUCC_PTR(search_ptr), ptr);
            SET_PTR(SUCC_PTR(ptr), insert_ptr);
            SET_PTR(PRED_PTR(insert_ptr), ptr);
        } else {
            SET_PTR(PRED_PTR(ptr), search_ptr);
            SET_PTR(SUCC_PTR(search_ptr), ptr);
            SET_PTR(SUCC_PTR(ptr), NULL);
            segregated_free_lists[list] = ptr;
        }
    } else {
        if (insert_ptr != NULL) {
            SET_PTR(PRED_PTR(ptr), NULL);
            SET_PTR(SUCC_PTR(ptr), insert_ptr);
            SET_PTR(PRED_PTR(insert_ptr), ptr);
        } else {
            SET_PTR(PRED_PTR(ptr), NULL);
            SET_PTR(SUCC_PTR(ptr), NULL);
            segregated_free_lists[list] = ptr;
        }
    }
    
    return;
}
static void insert_node(void *ptr, size_t size) {
 // int list = 0;
  //void *search_ptr = ptr;
  //void *insert_ptr = NULL;
  char *bp;
  if ( head!= 0) {
	  bp = head;
	  SET_PTR(PRED_PTR(bp), ptr);
	  SET_PTR(SUCC_PTR(ptr), bp);      
	  SET_PTR(PRED_PTR(ptr), NULL);
      head = ptr; 
  } else {
	  head = ptr;
      SET_PTR(SUCC_PTR(ptr), NULL);
      SET_PTR(PRED_PTR(ptr), NULL);
      //(SUCC(ptr), NULL);
      //PUT(PRED(ptr), NULL);
	  //PUT(PRED_PTR(ptr),NULL);
	  //PUT(SUCC_PTR(ptr),NULL);
  }

      

  /* Select segregated list */
 /* while ((list < LISTS - 1) && (size > 1)) {
    size >>= 1;
    list++;
  }*/

  /* Select location on list to insert pointer while keeping list
     organized by byte size in ascending order. */
 /* search_ptr = free_lists[list];
  while ((search_ptr != NULL) && (size > GET_SIZE(HEAD(search_ptr)))) {
    insert_ptr = search_ptr;
    search_ptr = PRED(search_ptr);
  }

  // Set predecessor and successor 
  if (search_ptr != NULL) {
    if (insert_ptr != NULL) {
      SET_PTR(PRED_PTR(ptr), search_ptr);
      SET_PTR(SUCC_PTR(search_ptr), ptr);
      SET_PTR(SUCC_PTR(ptr), insert_ptr);
      SET_PTR(PRED_PTR(insert_ptr), ptr);
    } else {
      SET_PTR(PRED_PTR(ptr), search_ptr);
      SET_PTR(SUCC_PTR(search_ptr), ptr);
      SET_PTR(SUCC_PTR(ptr), NULL);

      // Add block to appropriate list 
      free_lists[list] = ptr;
    }
  } else {
    if (insert_ptr != NULL) {
      SET_PTR(PRED_PTR(ptr), NULL);
      SET_PTR(SUCC_PTR(ptr), insert_ptr);
      SET_PTR(PRED_PTR(insert_ptr), ptr);
    } else {
      SET_PTR(PRED_PTR(ptr), NULL);
      SET_PTR(SUCC_PTR(ptr), NULL);

      // Add block to appropriate list 
      free_lists[list] = ptr;
    }
  } */

  return;
}