• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PREV_BLKP函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GET_ALLOC

static void *coalesce(void *ptr)
{
    size_t prev_alloc = GET_ALLOC(HDRP(PREV_BLKP(ptr)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(ptr)));
    size_t size = GET_SIZE(HDRP(ptr));
    

    // Do not coalesce with previous block if the previous block is tagged with Reallocation tag
    if (GET_TAG(HDRP(PREV_BLKP(ptr))))
        prev_alloc = 1;

    if (prev_alloc && next_alloc) {                         // Case 1
        return ptr;
    }
    else if (prev_alloc && !next_alloc) {                   // Case 2
        delete_node(ptr);
        delete_node(NEXT_BLKP(ptr));
        size += GET_SIZE(HDRP(NEXT_BLKP(ptr)));
        PUT(HDRP(ptr), PACK(size, 0));
        PUT(FTRP(ptr), PACK(size, 0));
    } else if (!prev_alloc && next_alloc) {                 // Case 3 
        delete_node(ptr);
        delete_node(PREV_BLKP(ptr));
        size += GET_SIZE(HDRP(PREV_BLKP(ptr)));
        PUT(FTRP(ptr), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(ptr)), PACK(size, 0));
        ptr = PREV_BLKP(ptr);
    } else {                                                // Case 4
        delete_node(ptr);
        delete_node(PREV_BLKP(ptr));
        delete_node(NEXT_BLKP(ptr));
        size += GET_SIZE(HDRP(PREV_BLKP(ptr))) + GET_SIZE(HDRP(NEXT_BLKP(ptr)));
        PUT(HDRP(PREV_BLKP(ptr)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(ptr)), PACK(size, 0));
        ptr = PREV_BLKP(ptr);
    }
    
    insert_node(ptr, size);
    
    return ptr;
}
开发者ID:gowtamvamsi,项目名称:Malloc-Lab,代码行数:41,代码来源:mm.c


示例17: PREV_BLKP

//
// coalesce - boundary tag coalescing. Return ptr to coalesced block
//
static void *coalesce(void *bp)
{
  FL_Pointer prev = PREV_BLKP(bp);
  FL_Pointer next = NEXT_BLKP(bp);

  size_t prev_alloc = GET_ALLOC(FTRP(prev));
  size_t next_alloc = GET_ALLOC(HDRP(next));
  size_t size = GET_SIZE(HDRP(bp));

  //CASE 1 : Both neighbors are allocated
  if (prev_alloc && next_alloc) {
    // we need to add free list node here b/c we do not do it in mm_free
    CL_append(&free_list, bp);
  }

  //CASE 2 : Only next free
  else if (prev_alloc && !next_alloc) {

    // unlink node thats next, b/c our current position will be beggining of new free node
    CL_unlink(next);
    CL_append(&free_list, bp);

    size += GET_SIZE(HDRP(next));
    PUT(HDRP(bp), PACK(size,0));
    PUT(FTRP(bp), PACK(size,0));
  }

  //CASE 3 : Only prev free
  else if (!prev_alloc && next_alloc){
    size += GET_SIZE(HDRP(prev));

    // no need to make new here b/c one exists at prev_node
    PUT(FTRP(bp), PACK(size,0));
    PUT(HDRP(prev), PACK(size,0));
    bp = prev;
  }

  //CASE 4 : both neighbors unallocated
  else {
    size += GET_SIZE(HDRP(prev))
      + GET_SIZE(FTRP(next));

    // unlink node that is above us, we can ignore the one below us because that
    // will serve ad the head for this free block
    CL_unlink(next);
    PUT(HDRP(prev), PACK(size,0));
    PUT(FTRP(next), PACK(size,0));
    bp = prev;

  }

  return bp;
}
开发者ID:NguyenTrav,项目名称:mmalloc,代码行数:56,代码来源:mm.c


示例18: 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) 
{
	printf("Start coalesce\n");
	if (bp == NULL)
		printf("Pointer is NULL\n");
	struct node *new_node;	
	size_t size = GET_SIZE(HDRP(bp));
	
	printf("Got size\n");
	bool prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
	printf("Stored whether previous block was allocated\n");
	bool next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
	printf("Stored whether the next block was allocated\n");
	printf("Finished coalesce initializations\n");
	if (prev_alloc && next_alloc) {                 /* Case 1 */
		printf("Case 1\n");
		return (bp);
	} else if (prev_alloc && !next_alloc) {         /* Case 2 */
		printf("Case 2\n");
		size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
		splice((struct node *)NEXT_BLKP(bp));
	} else if (!prev_alloc && next_alloc) {         /* Case 3 */
		printf("Case 3\n");
		size += GET_SIZE(HDRP(PREV_BLKP(bp)));
		PUT(FTRP(bp), PACK(size, 0));
		PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));

		/* Seems to work for now, but rather hackish */
		/* the issue arises because bp is not actually in the list yet (I think) */
		struct node *temp = (struct node *)bp;
		if (temp->next != NULL)
			splice(bp);
		bp = PREV_BLKP((void *)bp);
	} else {                                        /* Case 4 */
		printf("Case 4\n");
		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));
		splice((struct node *)bp);
		splice((struct node *)NEXT_BLKP(bp));
		bp = PREV_BLKP(bp);
	}
	
	new_node = (struct node *)coalesce(bp);
	new_node->next = list_start;
	new_node->previous = NULL;
	list_start->previous = new_node;
	list_start = new_node;
	checkheap(1);
	return (bp);
}
开发者ID:gowtamvamsi,项目名称:COMP321-malloc,代码行数:63,代码来源:mm.c


示例19: ASSERT

static char *coalesce(char *bp) 
{
  ASSERT(bp != NULL) ;
    size_t prev_alloc = GETALLOC(FTRP(PREV_BLKP(bp)));
    size_t next_alloc = GETALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GETSIZE(HDRP(bp));

    if (prev_alloc && next_alloc) {            /* Case 1 */      
      FL_insert(bp) ;
      
    }

    else if (prev_alloc && !next_alloc) {      
      /* Case 2 , bottom free*/
      FL_remove((char*)(NEXT_BLKP(bp))) ; //remove next block from free list
      size += GETSIZE(HDRP(NEXT_BLKP(bp)));
      PUT(HDRP(bp), PACK(size, 0));
      PUT(FTRP(bp), PACK(size,0));
      FL_insert((char*)bp) ; // insert new block into free list 
    }

    else if (!prev_alloc && next_alloc) {      /* Case 3 */
      //prev is free, next is alloc
      FL_remove((char*)(PREV_BLKP(bp))) ; // remove prev block from free list
      size += GETSIZE(HDRP(PREV_BLKP(bp)));
      PUT(FTRP(bp), PACK(size, 0));
      PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
      bp = PREV_BLKP(bp);
      FL_insert((char*)bp) ; // add new block to free list
    }

    else {                                     /* Case 4 */
      //remove both top and bottom from free list
      FL_remove((char*)(PREV_BLKP(bp))) ;
      FL_remove((char*)(NEXT_BLKP(bp))) ;
   
      size += GETSIZE(HDRP(PREV_BLKP(bp))) + GETSIZE(HDRP(NEXT_BLKP(bp)));
      PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
      PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
      bp = PREV_BLKP(bp);
      FL_insert((char*)bp) ; // insert modified block back
    }
    ASSERT(bp == firstFBP) ;
    return (char*)bp ;
}
开发者ID:sam1323123,项目名称:Projects,代码行数:45,代码来源:mem_exp.c


示例20: GET_PREV_ALLOC

/*
 * coalesce - Implements boundary-tag coalescing to merge the input block 
 * with any adjacent free blocks in constant time.
 */
static void *coalesce(void *bp) {
    size_t prev_alloc = GET_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 */
        UNSET_TAG(HDRP(NEXT_BLKP(bp)));    
        add_to_list(find_list(GET_SIZE(HDRP(bp))), bp);
        return bp;
    }
    else if (prev_alloc && !next_alloc) {      /* Case 2 */
        remove_from_list(find_list(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp));
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size,0));
        SET_TAG(HDRP(bp));
        SET_TAG(FTRP(bp));
    }
    else if (!prev_alloc && next_alloc) {      /* Case 3 */
        remove_from_list(find_list(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);
    }
    else {                                     /* Case 4 */
        remove_from_list(find_list(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp));
        remove_from_list(find_list(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);
    }
    
    UNSET_TAG(HDRP(NEXT_BLKP(bp)));    
    add_to_list(find_list(GET_SIZE(HDRP(bp))), bp);

    return bp;
}
开发者ID:csukuangfj,项目名称:15-213-Introduction-to-Computer-Systems,代码行数:43,代码来源:mm.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PRF_CLIENT_GET_ENV函数代码示例发布时间:2022-05-30
下一篇:
C++ PREV函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap