Esempio n. 1
0
File: mm.c Progetto: nik-6947/malloc
/*Removing a block from the free list either due to allocation or during coalascing*/
static void remove_list(void *bp){
  if (GET_PREVP(bp))
    SET_NEXTP(GET_PREVP(bp), GET_NEXTP(bp));
  else
    list_head = GET_NEXTP(bp);
  SET_PREVP(GET_NEXTP(bp), GET_PREVP(bp));
}
Esempio n. 2
0
/**
 * print_free_block - Print the contents of the given free block, including 
 *                    the pointers
 * @param bp Block to be printed
 */
static void print_free_block(void *bp) 
{
    size_t hsize = -1, halloc, fsize, falloc;

    if(bp != NULL) {
    hsize = GET_SIZE(HDRP(bp));
    halloc = GET_ALLOC(HDRP(bp));  
    fsize = GET_SIZE(FTRP(bp));
    falloc = GET_ALLOC(FTRP(bp));  
    dbg_printf("%p: header: [%lu:%c] footer: [%lu:%c]\n", bp,hsize, \
        (halloc ? 'a' : 'f'), fsize, (falloc ? 'a' : 'f')); 
    dbg_printf( "%p: next: [%p] prev: [%p]\n  ", bp, GET_NEXTP(bp), \
        GET_PREVP(bp) );
    } else {
        dbg_printf("bp is null\n");
    }

    if (hsize == 0) {
        dbg_printf("%p: EOL\n", bp);
        return;
    }
}
Esempio n. 3
0
/**
 * delete_free_list - Delete a block from the free seg list
 * @param bp block to be deleted from free list
 */
static  inline void delete_free_list(void *bp)
{
    int list_no = get_list_no(GET_SIZE(HDRP(bp)));
    temp++;
    void *next = GET_NEXTP(bp);
    void *prev = GET_PREVP(bp);
    /*Handle corner case of deleting head node.*/
    if(bp == GET_SEGI(seg_list, list_no) ) {
        SET_SEGI(seg_list, list_no, next);
    }

    if(prev != NULL) {
        SET_NEXTP(prev, next);
    }

    if(next != NULL) {
        SET_PREVP(next, prev);
    }

    /*Clean Up task. Set next/prev pointers of bp to NULL*/
    SET_NEXTP(bp,NULL);
    SET_PREVP(bp,NULL);
}
Esempio n. 4
0
/**
 * check_seg_pointers - Check the seg lists for correctness of all the previous
 *                      and next pointers
 */
static void check_seg_pointers()
{
    void *bp;
    void *next;
    size_t asize;

    /* Check for all the pointers in the blocks to be correct */
    for (int i = 0; i < NO_OF_LISTS; i++) {
        for (bp = GET_SEGI(seg_list,i); (bp!=NULL) 
          &&  (GET_SIZE(HDRP(bp)) > 0);bp = GET_NEXTP(bp)) {
            next = GET_NEXTP(bp);
            asize = GET_SIZE(HDRP(bp));
            /*Check for correct bucket*/
            if( (int)get_list_no(asize) != i  ) {
                printf("ERROR: Belong to wrong seg list %p\n",bp );
            }

            if( next != NULL && GET_PREVP(next) != bp) {
                printf("ERROR: Link at block %p is broken\n",bp );
            }
        }   
    }
}