当前位置: 首页>>代码示例>>C++>>正文


C++ PREV_BLKP函数代码示例

本文整理汇总了C++中PREV_BLKP函数的典型用法代码示例。如果您正苦于以下问题:C++ PREV_BLKP函数的具体用法?C++ PREV_BLKP怎么用?C++ PREV_BLKP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PREV_BLKP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GET_ALLOC

/**********************************************************
 * Covers the 4 cases discussed in the text:
 * - both neighbours are allocated
 * - the next block is available for coalescing
 * - the previous block is available for coalescing
 * - both neighbours are available for coalescing

 *  The coalesce has four conditions based on
 *  the neighbours around it
 *  basically if there is a free neighbour,
 *  we need to modify the header and footer 
 *  of the left most neightbour to coalesce the new size.
 *  But as well, since we need to remove the coalesced free
 *  block from the free list and re add the new larger block
 *  onto the free list.
 **********************************************************/
void *coalesce(void *bp)
{
    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));
    if (bp == NULL)
        return NULL;

    if (prev_alloc && next_alloc) {       /* Case 1 */
    insertFifoFreeBlock(bp);              // Insert onto free list
        return bp;
    }

    else if (prev_alloc && !next_alloc) { /* Case 2 */
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        delete_from_free (NEXT_BLKP(bp));   // Remove the right block from the free list
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));

        insertFifoFreeBlock(bp);           // Insert onto free list
        return (bp);
    }

    else if (!prev_alloc && next_alloc) { /* Case 3 */
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        delete_from_free (PREV_BLKP(bp));      // Remove the left block from the free list
        PUT(FTRP(bp), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));

        bp = PREV_BLKP(bp);

        insertFifoFreeBlock(bp);             // Insert onto free list

        return (bp);
    }

    else {            /* Case 4 */
        size += GET_SIZE(HDRP(PREV_BLKP(bp)))  +
        GET_SIZE(FTRP(NEXT_BLKP(bp)))  ;

        delete_from_free (PREV_BLKP(bp));       // Remove the left block from the free list
        delete_from_free (NEXT_BLKP(bp));        // Remove the right block from the free list
        PUT(HDRP(PREV_BLKP(bp)), PACK(size,0));
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size,0));

        bp = PREV_BLKP(bp);

        insertFifoFreeBlock(bp);                // Insert onto free list
        return (bp);
    }
}
开发者ID:chznight,项目名称:assn3-malloc,代码行数:67,代码来源:mm.c

示例2: GET_ALLOC

static void *coalesce(void *bp){
    size_t previous_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp))) || PREV_BLKP(bp) == bp;       
    size_t next__alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));                                 
    size_t size = GET_SIZE(HDRP(bp));                                                    

    if(previous_alloc && !next__alloc){                                                  
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));                                           
        mm_remove(NEXT_BLKP(bp));                                                        
        PUT(HDRP(bp), PACK(size, 0));                                                       
        PUT(FTRP(bp), PACK(size, 0));                                                       
    }

    else if(!previous_alloc && next__alloc){                                                
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));                                              
        bp = PREV_BLKP(bp);                                                              
        mm_remove(bp);                                                                   
        PUT(HDRP(bp), PACK(size, 0));                                                      
        PUT(FTRP(bp), PACK(size, 0));                                                      
    }

    else if(!previous_alloc && !next__alloc){                                        
        size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(HDRP(NEXT_BLKP(bp)));       
        mm_remove(PREV_BLKP(bp));                                                    
        mm_remove(NEXT_BLKP(bp));                                                    
        bp = PREV_BLKP(bp);                                                          
        PUT(HDRP(bp), PACK(size, 0));                                                
        PUT(FTRP(bp), PACK(size, 0));                                                
    }
    mm_insert(bp);                                                                   
    return bp;
}
开发者ID:bremerle3,项目名称:cse361,代码行数:31,代码来源:mm_70.c

示例3: IS_PREV_ALLOC

/*
 * coalesce
 * Boundary tag coalescing. Return ptr to coalesced block
 * delete or insert entry of free list.
 */
static void *coalesce(void *bp) 
{
    size_t prev_alloc = IS_PREV_ALLOC(HDRP(bp));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));

    if (prev_alloc && next_alloc) {            /* Case 1 */
        /* nop */
    }
    else if (prev_alloc && !next_alloc) {      /* Case 2 */
        if (heap_tailp == NEXT_BLKP(bp)) {
            heap_tailp = bp;
        }
        delete_node(get_level(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp));
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK3(size, 2, 0));
        PUT(FTRP(bp), PACK3(size, 2, 0));
    }
    else if (!prev_alloc && next_alloc) {      /* Case 3 */
        int t = (bp == heap_tailp);
        delete_node(get_level(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp));
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        SET_SIZE(FTRP(bp), size);
        SET_SIZE(HDRP(PREV_BLKP(bp)), size);
        bp = PREV_BLKP(bp);
        if (t) {
            heap_tailp = bp;
        }
    }
    else {                                     /* Case 4 */
        int t = (NEXT_BLKP(bp) == heap_tailp);
        delete_node(get_level(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp));
        delete_node(get_level(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp));
        size += GET_SIZE(HDRP(PREV_BLKP(bp))) +  GET_SIZE(FTRP(NEXT_BLKP(bp)));
        SET_SIZE(HDRP(PREV_BLKP(bp)), size);
        SET_SIZE(FTRP(NEXT_BLKP(bp)), size);
        bp = PREV_BLKP(bp);
        if (t) {
            heap_tailp = bp;
        }
    }
    UNFLAG(HDRP(NEXT_BLKP(bp)));    
    insert_node(get_level(GET_SIZE(HDRP(bp))), bp);
    return bp;
}
开发者ID:cmxcn,项目名称:CSAPP_labs,代码行数:50,代码来源:refer3.c

示例4: GET_ALLOC

/*
 * Given a block pointer try to coalesce the previous and next
 * blocks if they are empty
 */
static void *coalesce(void *bp) {

    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));

    if (next_alloc && prev_alloc) {
        return bp;
    }
    else if (!prev_alloc && next_alloc) {
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        PUT(FTRP(bp), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
    }
    else if (prev_alloc && !next_alloc) {
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
    }
    else {
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
    }

    return bp;
}
开发者ID:ifthikhan,项目名称:homemade-mm,代码行数:34,代码来源:mm.c

示例5: if

//合并空闲块儿
static void *coalesce(void *bp)
{
	size_t prev_alloc=GET_ALLOC(FTRP(PREV_BLKP(bp)));		//获取前面块儿的已分配位
	size_t next_alloc=GET_ALLOC(HDRP(NEXT_BLKP(bp)));		//获取后面块儿的已分配位
	size_t size=GET_SIZE(HDRP(bp));							
	if(prev_alloc && next_alloc){
		return bp;						//前后都被占用   case1 
	}							
	else if(prev_alloc && !next_alloc){
		size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
	}									//前一个块儿空闲
	else if(!prev_alloc && next_alloc){
		
		size += GET_SIZE(HDRP(PREV_BLKP(bp)));
		PUT(FTRP(bp), PACK(size, 0));
		PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
		bp = PREV_BLKP(bp);
	}									//后一个块儿空闲
	else{
		size += GET_SIZE(HDRP(PREV_BLKP(bp)))+GET_SIZE(FTRP(NEXT_BLKP(bp)));
		PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
		PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
		bp = PREV_BLKP(bp);
	}									//前后块儿都空闲
	return bp;
}
开发者ID:scentsoul,项目名称:the_practice,代码行数:29,代码来源:mm_malloc.c

示例6: coalesce

void* coalesce(void *bp){

    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));

    if(prev_alloc && next_alloc)            /* Both Adjacent Blocks Are Allocated */
        return bp;

    else if(prev_alloc && !next_alloc){     /* Next is not allocated */ 
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK(size,0));
        PUT(FTRP(bp), PACK(size,0));
    }

    else if(!prev_alloc && next_alloc){     /* Prev is not allocated */
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        PUT(FTRP(bp), PACK(size,0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
    }

    else{                                   /* Both are not allocated */
        size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(FTRP(NEXT_BLKP(bp)));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
    }

    return bp;
}
开发者ID:jboullianne,项目名称:csc252,代码行数:31,代码来源:mm.c

示例7: coalesce

/*
 * Requires:
 *   "bp" is the address of a newly freed block.
 *
 * Effects:
 *   Perform boundary tag coalescing. 
 */
static void *
coalesce(void *bp)
{
  size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
  size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp))) || PREV_BLKP(bp) == bp;
  size_t size = GET_SIZE(HDRP(bp));
  
  /* Next block is free */   
  if (prev_alloc && !next_alloc) {                  
    size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
    remove_list(NEXT_BLKP(bp));
    PUT(HDRP(bp), PACK(size, 0));
    PUT(FTRP(bp), PACK(size, 0));
  }
  /* Previous block is free */  
  else if (!prev_alloc && next_alloc) {               
    size += GET_SIZE(HDRP(PREV_BLKP(bp)));
    bp = PREV_BLKP(bp);
    remove_list(bp);
    PUT(HDRP(bp), PACK(size, 0));
    PUT(FTRP(bp), PACK(size, 0));
  }
  /* Both blocks are free */ 
  else if (!prev_alloc && !next_alloc) {                
    size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(HDRP(NEXT_BLKP(bp)));
    remove_list(PREV_BLKP(bp));
    remove_list(NEXT_BLKP(bp));
    bp = PREV_BLKP(bp);
    PUT(HDRP(bp), PACK(size, 0));
    PUT(FTRP(bp), PACK(size, 0));
  }
  /*insert bp,free block into free list*/
  insert_list(bp);
  return bp;
}
开发者ID:nik-6947,项目名称:malloc,代码行数:42,代码来源:mm.c

示例8: coalesce

/*
 * Requires:
 *   "bp" is the address of a newly freed block.
 *
 * Effects:
 *   Perform boundary tag coalescing.  Returns the address of the coalesced
 *   block.
 */
static void *
coalesce(void *bp) 
{
	size_t size = GET_SIZE(HDRP(bp));
	bool prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
	bool next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));

	if (prev_alloc && next_alloc) {                 /* Case 1 */
		return (bp);
	} else if (prev_alloc && !next_alloc) {         /* Case 2 */
		size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
	} else if (!prev_alloc && next_alloc) {         /* Case 3 */
		size += GET_SIZE(HDRP(PREV_BLKP(bp)));
		PUT(FTRP(bp), PACK(size, 0));
		PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
		bp = PREV_BLKP(bp);
	} else {                                        /* Case 4 */
		size += GET_SIZE(HDRP(PREV_BLKP(bp))) + 
		    GET_SIZE(FTRP(NEXT_BLKP(bp)));
		PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
		PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
		bp = PREV_BLKP(bp);
	}
	return (bp);
}
开发者ID:gowtamvamsi,项目名称:COMP321-malloc,代码行数:35,代码来源:mm_lab.c

示例9: GET_ALLOC

static void *coalescing(void *bp)   // combining neighbouring free blocks
	{ 
	size_t prev_allocated = GET_ALLOC(FTRP(PREV_BLKP(bp)));  // status of next block
	size_t next_allocated = GET_ALLOC(HDRP(NEXT_BLKP(bp)));  // status of previous free block                               
	size_t size = GET_SIZE(HDRP(bp));                    // size of the header                            

	if (prev_allocated && next_allocated) { return bp;  }         // both neighboring blocks are allocated
	else if (prev_allocated && !next_allocated) {                 // previous block is allocated & next block is free
	  	size += GET_SIZE(HDRP(NEXT_BLKP(bp)));        
                PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
                PUT(HDRP(bp), PACK(size, 0));
                

	}
	else if (!prev_allocated && next_allocated) {                  // previous block is free & next block is allocated
		size += GET_SIZE(HDRP(PREV_BLKP(bp))); 
		PUT(FTRP(bp), PACK(size, 0)); 
		PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
	 	bp = PREV_BLKP(bp); 
   	}	
	else if (!prev_allocated && !next_allocated) {                 // both neighboring blocks are free
		size += GET_SIZE(HDRP(PREV_BLKP(bp)))+GET_SIZE(HDRP(NEXT_BLKP(bp)));
                PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
                PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
                bp = PREV_BLKP(bp);

	}
	return bp;
}
开发者ID:desaivaibhavi,项目名称:shell-project,代码行数:29,代码来源:mm.c

示例10: GET_ALLOC

/*
 * coalesce the previous block-curent block-next block
    IF handled corrected, each free will call this method, and no two consecutive freed block would exsist.
 */
static void *coalesce(void *bp){
    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));

    if(prev_alloc && next_alloc)
        return bp;

    else if(prev_alloc && !next_alloc){
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
    }else if(!prev_alloc && next_alloc){
        size += GET_SIZE(FTRP(PREV_BLKP(bp)));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
        bp = PREV_BLKP(bp);
    }else{
        size += GET_SIZE(HDRP(NEXT_BLKP(bp))) + GET_SIZE(FTRP(PREV_BLKP(bp)));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
    }

    if((rover > (char*)bp) && (rover < NEXT_BLKP(bp)))
        rover = bp;

    return bp;
}
开发者ID:cmxcn,项目名称:CSAPP_labs,代码行数:33,代码来源:mm_Impl_nf.c

示例11: GET_ALLOC

/*
 * coalesce - ser um ad smida/setja saman free lista sem eru hlid vid hlid
 * tryggir tad ad aldrei seu tveir samliggjandi free blockir
 */
static void *coalesce(void *bp) {
    size_t prev_alloc;
    if (PREV_BLKP(bp) == bp) {
        prev_alloc = 1;
    }
    else
        prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));

    // CASE 1 : PREV fratekid og NEXT fratekid
    if (prev_alloc && next_alloc) {
        //printf("CASE 1\n");
        // Baeta vidkomandi fremst i free list
        addBlckToFreeList(bp);
        return bp;
        // CASE 2 : PREV fratelod pg MEXT laust
    } else if (prev_alloc && !next_alloc) {
        //printf("CASE 2\n");
        // Finna staerdina a nyju friu blokkini
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        // Fjarlaegja blokkina a eftir i burtu
        removeBlckFromFreeList(NEXT_BLKP(bp));
        // Fria blokkina
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
        // CASE 3 : PREV laust og PREV fratekid
    } else if (!prev_alloc && next_alloc) {
        //printf("CASE 3\n");
        // Finna staerdina a nyju friu blokkini
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        // Fria blokkina
        PUT(FTRP(bp), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
        // Fjarlaegja blokkina a undan i burtu
        removeBlckFromFreeList(bp);
        // CASE 4 : PREV laust og NEXT laust
    } else {
        //printf("CASE 4\n");
        // Finna staerdina a nyju friu blokkini
        size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(FTRP(NEXT_BLKP(bp)));
        // Fjarlaegja blokkirnar a undan og eftir i burtu.
        removeBlckFromFreeList(PREV_BLKP(bp));
        removeBlckFromFreeList(NEXT_BLKP(bp));
        // Fria bada blokkirnar
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
        PUT(HDRP(bp), PACK(size, 0));
    }
    // Baeta vidkomandi fremst i free list
    // A vid um CASE 2 , 3 og 4!
    addBlckToFreeList(bp);
    return bp;
}
开发者ID:johannbrynjar,项目名称:malloclab,代码行数:59,代码来源:mm.c

示例12: GET_ALLOC

/*
 * Requires:
 *   "bp" is the address of a newly freed block.
 *
 * Effects:
 *   Perform boundary tag coalescing.  Returns the address of the coalesced
 *   block.
 */
static void 
*coalesce(void *bp)
{
	bool prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
	bool next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
	size_t size = GET_SIZE(HDRP(bp));

	if (PREV_BLKP(bp) == bp) {
		prev_alloc = true;
	}

	/* a-a-a */
	/* insert self at beginning of free list */
	if (prev_alloc && next_alloc) {                 /* Case 1 */
		addToBeginningOfFreeList(bp);
	} 

	/* a-a-f */
	/* splice out next, coalesce self and next, and add to beginning of free list */
	else if (prev_alloc && !next_alloc)             /* Case 2 */
	{			
		size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
		removeBlockFromList(NEXT_BLKP(bp));
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
		addToBeginningOfFreeList(bp);
	}

	/* f-a-a */
	/* splice out prev, coalesce with self, and add to beginning of free list */
	else if (!prev_alloc && next_alloc)             /* Case 3 */
	{		
		size += GET_SIZE(HDRP(PREV_BLKP(bp)));
		bp = PREV_BLKP(bp);
		removeBlockFromList(bp);
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
		addToBeginningOfFreeList(bp);
	}

	/* f-a-f */
	/* splice out prev and next, coalesce with self, and add to beginning of list */
	else if (!prev_alloc && !next_alloc)                                       /* Case 4 */
	{		
		size += GET_SIZE(HDRP(PREV_BLKP(bp))) + 
				GET_SIZE(HDRP(NEXT_BLKP(bp)));
		removeBlockFromList(PREV_BLKP(bp));
		removeBlockFromList(NEXT_BLKP(bp));
		bp = PREV_BLKP(bp);
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
		addToBeginningOfFreeList(bp);
	}

       	free_listp = bp;           /* start of the new free list is at the block that has been put at front of list */
	return bp;

}
开发者ID:jcjcarter,项目名称:Malloc,代码行数:66,代码来源:mm.c

示例13: GET_ALLOC

/* $begin mmfree */
static void *coalesce(void *bp)
{
    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));

    if (prev_alloc && next_alloc) {            /* Case 1: Neighbors both allocated */
        return bp;
    }

    else if (prev_alloc && !next_alloc) {      /* Case 2: Only the previous is allocated*/
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));

        /* If only the previous block is allocated, remove the next block */
        tree_root = mm_remove(tree_root, NEXT_BLKP(bp));

        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size,0));

        return(bp);
    }

    else if (!prev_alloc && next_alloc) {      /* Case 3: Only the next is allocated */
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));

        /* If only the next block is allocated, remove the previous block */
        tree_root = mm_remove(tree_root, PREV_BLKP(bp));

        PUT(FTRP(bp), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));

        return(PREV_BLKP(bp));
    }

    else {                                     /* Case 4: Neither are allocated */
        size += GET_SIZE(HDRP(PREV_BLKP(bp))) +
                GET_SIZE(FTRP(NEXT_BLKP(bp)));

        /* If neither blocks are allocated, remove them both */
        tree_root = mm_remove(tree_root, NEXT_BLKP(bp));
        tree_root = mm_remove(tree_root, PREV_BLKP(bp));

        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));

        return(PREV_BLKP(bp));
    }
}
开发者ID:BrandonSpitler,项目名称:malloclab,代码行数:49,代码来源:mm.c

示例14: GET

/*
 * coalesce
 * coalesce consecutive free blocks
 * use hdr and ftr to do constant time coalesce
 */
void *coalesce(void *bp){
	size_t prev_alloc = GET(FTRP(PREV_BLKP(bp))) & 0x1;
	size_t next_alloc = GET_ALLOC(NEXT_BLKP(bp));
	if(prev_alloc && next_alloc){
		/* prev/next blocks are not free */
	}else if(prev_alloc && !next_alloc){
		/* next block is free */
		coalesce_next(bp);
	}else if(!prev_alloc && next_alloc){
		/* prev block is free */
		bp = PREV_BLKP(bp);
		coalesce_next(bp);
	}else{
		coalesce_next(bp);
		bp = PREV_BLKP(bp);
		coalesce_next(bp);
	}
	return bp;
}
开发者ID:yihanwan,项目名称:15513,代码行数:24,代码来源:mm.c

示例15: GET_ALLOC

/*
 * coalesce - Boundary tag coalescing. Return ptr to coalesced block
 */
static void *coalesce(void *bp) 
{
    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));

    if (prev_alloc && next_alloc) {
        return bp;
    }

    else if (prev_alloc && !next_alloc) {
        delete_node(bp);
        delete_node(NEXT_BLKP(bp));      /* Case 2 */
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size,0));
    }

    else if (!prev_alloc && next_alloc) {      /* Case 3 */
        delete_node(bp);
        delete_node(PREV_BLKP(bp));
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        PUT(FTRP(bp), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
    }

    else {
        delete_node(bp);
        delete_node(PREV_BLKP(bp));
        delete_node(NEXT_BLKP(bp));
                                                    /* Case 4 */
        size += GET_SIZE(HDRP(PREV_BLKP(bp))) + 
            GET_SIZE(FTRP(NEXT_BLKP(bp)));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
    }
#ifdef NEXT_FIT
    /* Make sure the rover isn't pointing into the free block */
    /* that we just coalesced */
    if ((rover > (char *)bp) && (rover < NEXT_BLKP(bp))) 
        rover = bp;
#endif
    insert_node(bp, size);
    return bp;
}
开发者ID:PoojaManglaCMU,项目名称:MallocImplementation,代码行数:50,代码来源:mm_trace.c


注:本文中的PREV_BLKP函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。