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

C++ GET_ALLOC函数代码示例

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

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



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

示例1:

static inline void *find_fit(size_t asize)
{
  void *bp;
  for (bp = heap_listp; GET_SIZE(HDRP(bp))>0; bp = NEXT_BLKP(bp)) {
    if (!GET_ALLOC(HDRP(bp)) && (asize <= GET_SIZE(HDRP(bp))))
      return bp;
  }
  return NULL;
}
开发者ID:alexmadjar,项目名称:213malloc,代码行数:9,代码来源:mm-implicit.c


示例2: GET_ALLOC

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) //101
    {
        add_free(bp);
        //return bp;
    }

    else if(prev_alloc && !next_alloc) //100
    {
        rm_free(NEXT_BLKP(bp));

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

        add_free(bp);
    }

    else if(!prev_alloc && next_alloc) //001
    {
        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 //000
    {
        rm_free(NEXT_BLKP(bp));

        size += GET_SIZE(HDRP(NEXT_BLKP(bp))) + 
                GET_SIZE(HDRP(PREV_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:YeXiaoRain,项目名称:ICS_LAB,代码行数:44,代码来源:exp_mm(显式链表).c


示例3: GET_ALLOC

/*
 * coalesce - Coalesce adjacent free blocks. Sort the new free block into the
 *            appropriate list.
 */
static void *coalesce(void *ptr)
{
  size_t prev_alloc = GET_ALLOC(HEAD(PREV(ptr)));
  size_t next_alloc = GET_ALLOC(HEAD(NEXT(ptr)));
  size_t size = GET_SIZE(HEAD(ptr));

  /* Return if previous and next blocks are allocated */
  if (prev_alloc && next_alloc) {
    return ptr;
  }

  /* Do not coalesce with previous block if it is tagged */
  if (GET_TAG(HEAD(PREV(ptr))))
    prev_alloc = 1;

  /* Remove old block from list */
  delete_node(ptr);

  /* Detect free blocks and merge, if possible */
  if (prev_alloc && !next_alloc) {
    delete_node(NEXT(ptr));
    size += GET_SIZE(HEAD(NEXT(ptr)));
    PUT(HEAD(ptr), PACK(size, 0));
    PUT(FOOT(ptr), PACK(size, 0));
  } else if (!prev_alloc && next_alloc) {
    delete_node(PREV(ptr));
    size += GET_SIZE(HEAD(PREV(ptr)));
    PUT(FOOT(ptr), PACK(size, 0));
    PUT(HEAD(PREV(ptr)), PACK(size, 0));
    ptr = PREV(ptr);
  } else {
    delete_node(PREV(ptr));
    delete_node(NEXT(ptr));
    size += GET_SIZE(HEAD(PREV(ptr))) + GET_SIZE(HEAD(NEXT(ptr)));
    PUT(HEAD(PREV(ptr)), PACK(size, 0));
    PUT(FOOT(NEXT(ptr)), PACK(size, 0));
    ptr = PREV(ptr);
  }

  /* Adjust segregated linked lists */
  insert_node(ptr, size);

  return ptr;
}
开发者ID:bloveless,项目名称:malloclab,代码行数:48,代码来源:mm_ref0.c


示例4: coalesce

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 previous and next are allocated do nothing */
    if (prev_alloc && next_alloc)

    {
    return bp;
    }


/* if next is not allocated */
 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));
    /* this node's successor is the next node's */
    size_t oldSucc = SCRP(NEXT_BLKP(bp));
    PUT(SCRP(bp), oldSucc);

    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));

    size_t oldSucc = SCRP(PREV_BLKP(bp));
    PUT(SCRP(PREV_BLKP(bp)), oldSucc);

    return(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));
    return(PREV_BLKP(bp));
 }
}
开发者ID:hshelton,项目名称:cs4400,代码行数:44,代码来源:mm.c


示例5: GET_ALLOC

static void *coalesce(void *bp)
{
	size_t prev_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 (prev_alloc && next_alloc)
	{
		// Do nothing
	}

	else if (prev_alloc && !next_alloc)
	{
		size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
		remove_block(NEXT_BLKP(bp),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)));
		bp = PREV_BLKP(bp);
		remove_block(bp,GET_SIZE(HDRP(bp)));
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));

	}

	else
	{
		size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(HDRP(NEXT_BLKP(bp)));
		void *pbp = PREV_BLKP(bp);
		remove_block(pbp, GET_SIZE(HDRP(pbp)));
		void *nbp = NEXT_BLKP(bp);
		remove_block(nbp, GET_SIZE(HDRP(nbp)));
		bp = PREV_BLKP(bp);
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
	}

	insert_free_list(bp,size);
	return bp;
}
开发者ID:niloygupta,项目名称:malloclab,代码行数:44,代码来源:mm.c


示例6: GET_ALLOC

/*
 * coalesce - Boundary tag coalescing. Return ptr to coalesced block
 */
static void *coalesce(void *bp){

  size_t NEXT_ALLOC = GET_ALLOC(  HDRP(NEXT_BLK(bp))  );
  size_t PREV_ALLOC = GET_ALLOC(  HDRP(PREV_BLK(bp))  );
  //size_t PREV_ALLOC = GET_ALLOC(  FTRP(PREV_BLK(bp))  ) || PREV_BLK(bp) == bp;
  size_t size = GET_SIZE(HDRP(bp));
  
  /*return if the previous and next blocks are both allocated */
  if (PREV_ALLOC && NEXT_ALLOC)
  {
	return bp;
  }
  
  /*Remove old block from list*/
  delete_node(bp);
  
  if (PREV_ALLOC && !NEXT_ALLOC)
  {
	delete_node(NEXT_BLK(bp));
	size += GET_SIZE(HDRP(NEXT_BLK(bp)));
	PUT(HDRP(bp), PACK(size, 0));
	PUT(FTRP(bp), PACK(size, 0));
  }
  else if (!PREV_ALLOC && NEXT_ALLOC)
  {
	delete_node(PREV_BLK(bp));
	size += GET_SIZE(HDRP(PREV_BLK(bp)));
	PUT(FTRP(bp), PACK(size, 0));
	PUT(HDRP(PREV_BLK(bp)), PACK(size, 0));
	bp = PREV(bp);
  }
  else
  {
	delete_node(PREV_BLK(bp));
	delete_node(NEXT_BLK(bp));
	size += GET_SIZE(HDRP(PREV_BLK(bp))) + GET_SIZE(HDRP(NEXT_BLK(bp)));
	PUT(HDRP(PREV_BLK(bp)), PACK(size, 0));
	PUT(FTRP(NEXT_BLK(bp)), PACK(size, 0));
	bp = PREV_BLK(bp);
  }
  
  insert_node(bp, size);
  return bp;
}
开发者ID:peterhad313,项目名称:malloc-lab,代码行数:47,代码来源:mm.c


示例7: GET_ALLOC

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

    if (prev_alloc && next_alloc) {                 /* Case 1 */
        printf("Go into case 1\n");
        add_lst(ptr);
        return ptr;
    }

    else if (prev_alloc && !next_alloc) {           /* Case 2 */
        size += GET_SIZE(HDRP(NEXT_BLKP(ptr)));
        printf("Go into case 2\n");
        remove_lst(NEXT_BLKP(ptr));
        PUT(HDRP(ptr), PACK(size, 0));
        PUT(FTRP(ptr), PACK(size,0));
        add_lst(ptr);
    }

    else if (!prev_alloc && next_alloc) {           /* Case 3 */
        printf("Go into case 3\n");
        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);
        remove_lst(ptr);
        add_lst(ptr);
    }

    else {                                          /* Case 4 */
        printf("Go into case 4\n");
        size += GET_SIZE(HDRP(PREV_BLKP(ptr))) +
        GET_SIZE(FTRP(NEXT_BLKP(ptr)));
        remove_lst(NEXT_BLKP(ptr));
        PUT(HDRP(PREV_BLKP(ptr)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(ptr)), PACK(size, 0));
        ptr = PREV_BLKP(ptr);
        remove_lst(ptr);
        add_lst(ptr);
    }
    return ptr;
}
开发者ID:karn806,项目名称:MallocLab_H-K,代码行数:44,代码来源:mm_explict.c


示例8: printblock

static void printblock(void *bp) 
{
    size_t hsize, halloc, fsize, falloc;

    checkheap(0);
    hsize = GET_SIZE(HDRP(bp));
    halloc = GET_ALLOC(HDRP(bp));  
    fsize = GET_SIZE(FTRP(bp));
    falloc = GET_ALLOC(FTRP(bp));  

    if (hsize == 0) {
        printf("%p: EOL\n", bp);
        return;
    }

    /*  printf("%p: header: [%p:%c] footer: [%p:%c]\n", bp, 
	hsize, (halloc ? 'a' : 'f'), 
	fsize, (falloc ? 'a' : 'f')); */
}
开发者ID:illucination3782,项目名称:6-malloc,代码行数:19,代码来源:mm.c


示例9: printblock

static void printblock(void *bp) 
{
    size_t hsize, halloc, fsize, falloc;

   // checkheap(0);
    hsize = GET_SIZE(HDRP(bp));
    halloc = GET_ALLOC(HDRP(bp));  
    fsize = GET_SIZE(FTRP(bp));
    falloc = GET_ALLOC(FTRP(bp));  

    if (hsize == 0) {
		dbg_printf("%p: EOL\n", bp);
	return;
    }

     dbg_printf("%p: header: [%u:%c] footer: [%u:%c]\n", bp, 
	(uint32_t)	hsize, (halloc ? 'a' : 'f'), 
	(uint32_t)fsize, (falloc ? 'a' : 'f')); 
}
开发者ID:hailunz,项目名称:Computer_System_labs,代码行数:19,代码来源:mm-segok.c


示例10: GET_ALLOC

/* $begin coalesce */
static void *coalesce(void *bp) //bp point to header
{
	void *prev_block=prev_blkp(bp);
	void *next_block=next_blkp(bp);

    uint32_t prev_alloc = GET_ALLOC(prev_block);
    uint32_t next_alloc = GET_ALLOC(next_block);
    uint32_t size = GET_SIZE(bp);

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

    else if (prev_alloc && !next_alloc) {      /* Case 2 */
	size += GET_SIZE(next_block);
	delete_free_block(next_block);
	PUT(bp, PACK(size, 0));
	PUT(FTRP1(bp), PACK(size,0));
    }

    else if (!prev_alloc && next_alloc) {      /* Case 3 */
	size += GET_SIZE(prev_block);
	delete_free_block(prev_block);
	PUT(FTRP1(bp), PACK(size, 0));
	PUT(prev_block, PACK(size, 0));
	bp = prev_block;
    }

    else {                                     /* Case 4 */
	size += GET_SIZE(prev_block) + 
	    GET_SIZE(next_block);
	delete_free_block(prev_block);
	delete_free_block(next_block);

	PUT(prev_block, PACK(size, 0));
	PUT(FTRP1(next_block), PACK(size, 0));
	bp = prev_block;
    }

	add_free_block(bp);
	return bp;
	
}
开发者ID:hailunz,项目名称:Computer_System_labs,代码行数:44,代码来源:mm4.c


示例11: printblock

static void printblock(void *bp) 
{
  size_t hsize, halloc, fsize, falloc;

  hsize = GET_SIZE(HDRP(bp));
  halloc = GET_ALLOC(HDRP(bp));  
  fsize = GET_SIZE(FTRP(bp));
  falloc = GET_ALLOC(FTRP(bp));  
    
  if (hsize == 0) {
    printf("%p: EOL\n", bp);
    return;
  }

  printf("%p: header: [%d:%c] footer: [%d:%c]\n",
	 bp, 
	 (int) hsize, (halloc ? 'a' : 'f'), 
	 (int) fsize, (falloc ? 'a' : 'f')); 
}
开发者ID:CSUChico-CSCI540,项目名称:CSCI540-MallocLab,代码行数:19,代码来源:mm.c


示例12: coalesce

static void* coalesce(void *bp) //bp point to header
{
	//dbg_printf("coalesce %p\n",bp);
	void *prev_blk=PREV_BLKP(bp);
	void *next_blk=NEXT_BLKP(bp);
	size_t prev_alloc = GET_ALLOC(FTRP(prev_blk));
    size_t next_alloc = GET_ALLOC(HDRP(next_blk));
    size_t size = GET_SIZE(HDRP(bp));
	
    if (prev_alloc && next_alloc) {            /* Case 1 */
		add_free_block(bp);
		return bp;
    }

    else if (prev_alloc && !next_alloc) {      /* Case 2 */
		size += GET_SIZE(HDRP(next_blk));
		delete_free_block(next_blk);
		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_blk));
		delete_free_block(prev_blk);
		PUT(FTRP(bp), PACK(size, 0));
		PUT(HDRP(prev_blk), PACK(size, 0));
		bp = prev_blk;
    }

    else {                                     /* Case 4 */
		size += GET_SIZE(HDRP(prev_blk)) + 
	    GET_SIZE(FTRP(next_blk));
		delete_free_block(prev_blk);
		delete_free_block(next_blk);
		PUT(HDRP(prev_blk), PACK(size, 0));
		PUT(FTRP(next_blk), PACK(size, 0));
		bp = prev_blk;
   }

	add_free_block(bp);
    return bp;
	
}
开发者ID:hailunz,项目名称:Computer_System_labs,代码行数:43,代码来源:mm-efree.c


示例13: while

static void *find_fit(size_t size) {
  char *bp = heap_listp;
  while (GET_SIZE(HDRP(bp))) {
    if (!GET_ALLOC(HDRP(bp)) && GET_SIZE(HDRP(bp)) >= size) {
      return bp;
    }
    bp = NEXT_BLKP(bp);
  }
  return NULL;
}
开发者ID:gigi13164269,项目名称:blog-1,代码行数:10,代码来源:mm.c


示例14: find_fit

void* find_fit(size_t size){

    void* temp = heap_ptr;
    while(*NEXT_BLKP(temp) > 0){    //Keep on going while not footer block
        if(GET_ALLOC(temp) && (GET_SIZE(temp) > size))
            return temp;
        temp = NEXT_BLKP(temp);
    }
    return NULL; //Didn't find a block so returning NULL
}
开发者ID:jboullianne,项目名称:csc252,代码行数:10,代码来源:mm.c


示例15: GET_ALLOC

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) {
    	add_freelist(bp);      /* Case:1 Both previous block and next block are allocated*/
        return bp;
    }
    else if (!prev_alloc && next_alloc) {
   	void *prev = PREV_BLKP(bp);   /* Case:2  Previous is free and next block is allocated*/
        delete_freelist(prev);
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        PUT(FTRP(bp), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
    	add_freelist(PREV_BLKP(bp));
        
	return (PREV_BLKP(bp));
    }
    else if (prev_alloc && !next_alloc) {
  	void *next = NEXT_BLKP(bp);        /* Case:3 Previous is allocated and next block is free  */
        delete_freelist(next);
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
   	add_freelist(bp);
       
	return (bp);
    }
    else {           
    	void *prev = PREV_BLKP(bp); /* Case:4 Both previous and next block are free*/
        void *next = NEXT_BLKP(bp);
        delete_freelist(prev);
        delete_freelist(next);
        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));
	add_freelist(PREV_BLKP(bp));

        return (PREV_BLKP(bp));
    }
}
开发者ID:Frequently,项目名称:Malloc,代码行数:43,代码来源:malloc.c


示例16: mm_checkheap

/* 
 * mm_checkheap - Check the heap for consistency 
 */
void mm_checkheap(int verbose) 
{
	//printf("************ CHECK BEGIN ***************\n");
    char *bp = heap_listp;
	char *checkAll = heap_listp;
	int countblocks = -1;

    if (verbose) {
        printf("Heap: (%p)\n", heap_listp);
    }

    if ((GET_SIZE(HDRP(heap_listp)) != OVERHEAD) || !GET_ALLOC(HDRP(heap_listp))) {
        printf("Bad prologue header\n");
    }
    checkblock(heap_listp);
	
	
	 while(GET(SUCC(bp)) != 0){
		if(verbose == 1)
		 	printblock(bp);
		checkblock(bp);
		//countblocks++;
		bp = (char*)GET(SUCC(bp));
	}
	 if(verbose == 1)
		 printblock(bp);

    for (checkAll = heap_listp; GET_SIZE(HDRP(checkAll)) > 0; checkAll = NEXT_BLKP(checkAll)) {
		if(!GET_ALLOC(HDRP(checkAll)) && !block_in_free_list(checkAll)){
			printf("Block is marked free but not in free list\n");		
		}
        checkblock(checkAll);
		countblocks++;
    }

	//printf("Number of free blocks: %d\n", freeblockcount);
	//printf("Total number of blocks: %d\n", countblocks);
    
    if ((GET_SIZE(HDRP(checkAll)) != 0) || !(GET_ALLOC(HDRP(checkAll)))) {
        printf("Bad epilogue header\n");
    }
	//printf("****************** CHECK END ********************\n");
}
开发者ID:olikari,项目名称:malloclab,代码行数:46,代码来源:mm.c


示例17: checkblock

/**
 * checkblock - check the current block for consistency
 * @param bp Block to be checked
 */
static void checkblock(void *bp) 
{
    /**
     * Checks-
     * 1) Check for alignment
     * 2) Check for Header and Footer Match
     * 3) Check for the block to be in heap
     * 4) Check coalescing- no previous/next free blocks if current is free.
     */
    
    /*Check Block for alignment*/
    if ((size_t)bp % 8) {
       printf("ERROR: %p is not doubleword aligned\n", bp);
    }

    /*Check Block Header matching Footer*/
    if (GET(HDRP(bp)) != GET(FTRP(bp))) {
        printf("ERROR: header does not match footer\n");
        dbg_printf("**Debug Info \n");
        dbg_printf("Heap_listp = %p \n", heap_listp );
        dbg_printf("Block %p \n", bp );
    } 

    /* Check for if the block is in the heap */       
    if( !in_heap(bp)) {
        printf("ERROR: %p is not in heap \n", bp);        
    }

    /**
     * Concept : As all the blocks are iteratively checked, just checking
     *           next block for coalescing will suffice next/previous block
     *           checks.
     */    
    /* Check Coalescing with Next Block */
    if( GET_ALLOC(HDRP(bp)) ==0 && NEXT_BLKP(bp)!=NULL 
        && GET_ALLOC(HDRP(NEXT_BLKP(bp))) ==0 ) {
        printf("ERROR: %p is not coalesced with next block\n", bp);        
        print_all();
        exit(1);
    }

}
开发者ID:AceYuRanger,项目名称:MallocLab,代码行数:46,代码来源:mm.c


示例18: logg

/**********************************************************
 * coalesce
 * 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
 **********************************************************/
void *coalesce(void *bp)
{
    logg(4, "============ coalesce() starts ==============");
    logg(1, "coalesce() called with bp: %p; Previous block: %p header: %zx; Next block: %p header: %zx", bp, PREV_BLKP(bp), GET(HDRP(PREV_BLKP(bp))), NEXT_BLKP(bp), GET(HDRP(NEXT_BLKP(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 */
        logg(2, "Case 1: Both prev and next blocks are allocated. NO coalescing.");
    }
    else if (prev_alloc && !next_alloc) { /* Case 2 */
        logg(2, "Case2: Next block is free.");
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        remove_free_block(NEXT_BLKP(bp));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
    }
    else if (!prev_alloc && next_alloc) { /* Case 3 */
        logg(2, "Case3: Prev block is free.");
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        remove_free_block(PREV_BLKP(bp));
        bp = PREV_BLKP(bp);     // move bp one block ahead
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
    }
    else {            /* Case 4 */
        logg(2, "Case4: Both blocks are free.");
        size += GET_SIZE(HDRP(PREV_BLKP(bp)))  + GET_SIZE(HDRP(NEXT_BLKP(bp)))  ;
        remove_free_block(NEXT_BLKP(bp));
        remove_free_block(PREV_BLKP(bp));
        bp = PREV_BLKP(bp);
        PUT(HDRP(bp), PACK(size,0));
        PUT(FTRP(bp), PACK(size,0));
    }

    // Add the bp block to the beginning of free list of corresponding size.
    add_free_block(bp);
    logg(4, "============ coalesce() ends ==============");
    return bp;
}
开发者ID:tabletenniser,项目名称:ECE454_hw3,代码行数:50,代码来源:mm.c


示例19: GET_ALLOC

/*
 * coalesce - boundary tag coalescing.
 * This function joins adjecent free blocks together by
 * finding the size (newsize) of the new (bigger) free block, removing the
 * free block(s) from the free list, and changing the header
 * and footer information to the newly coalesced free block
 * (size = newsize, allocated = 0)
 * Then, we add the new free block to the front of the free list.
 *
 * This function takes a block pointer to the newly freed block (around which
 * we must coalesce) and returns the block pointer to the coalesced free
 * block.
 * Return ptr to coalesced block
 */
static void *coalesce(void *bp)
{
	size_t prev_alloc;
	prev_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));
    
	/* Case 1, extend the block leftward */
	if (prev_alloc && !next_alloc)
	{
		size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
		removeBlock(NEXT_BLKP(bp));
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
	}
    
	/* Case 2, extend the block rightward */
	else if (!prev_alloc && next_alloc)
	{
		size += GET_SIZE(HDRP(PREV_BLKP(bp)));
		bp = PREV_BLKP(bp);
		removeBlock(bp);
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
	}
    
	/* Case 3, extend the block in both directions */
	else if (!prev_alloc && !next_alloc)
	{
		size += GET_SIZE(HDRP(PREV_BLKP(bp))) +
        GET_SIZE(HDRP(NEXT_BLKP(bp)));
		removeBlock(PREV_BLKP(bp));
		removeBlock(NEXT_BLKP(bp));
		bp = PREV_BLKP(bp);
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
	}
	
	insertAtFront(bp);
	
	return bp;
}
开发者ID:liopei19nn,项目名称:15213_LIP,代码行数:56,代码来源:mm+13.c


示例20: mm_checkheap

/*
 * mm_checkheap - Checks the invariants of the heap
 * This function checks the invariants of the heap such as header-footer match,
 * absence of contiguous blocks of free memory and confirmation that the
 * block pointers are within the heaps boundaries.
 */
void mm_checkheap(int verbose)
{
  void *bp = heap_listp; //Points to the first block in the heap
  verbose = verbose;

  /* If first block's header's size or allocation bit is wrong,
   * the prologue header is incorrect. */

  if ((GET_SIZE(HDRP(heap_listp)) != MINBLOCKSIZE) ||
      !GET_ALLOC(HDRP(heap_listp)))
    printf("Bad prologue header\n");
  checkblock(bp);

  for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp))
    {
      if (verbose)
	printblock(bp);
      if(GET_SIZE(HDRP(bp)) == 0)
	printf("Error: block has zero size\n");
      checkblock(bp);

      /* Checking to see if free block in the free list */
      if(!GET_ALLOC(HDRP(bp)))
	checkInFreeList(bp);

    }

  /* If last block's header's size or allocation bit is wrong,
   * the epilogue's header is wrong. We also check the specific location
   * of the epilogue header with respect to the last byte of the heap.
   * mem_heap_hi() and bp(at this point) both point to the same word,
   * but mem_heap_hi() points to the last byte and hence we must add 3 to
   * the address of the header of bp to check this condition.
   */
  if (GET_SIZE(HDRP(bp)) != 0 || (GET_ALLOC(HDRP(bp)) != 1)
      || (HDRP(bp) + WSIZE - 1) != mem_heap_hi())
    printf("Bad epilogue header\n");

  for(bp = free_listp; GET_ALLOC(HDRP(bp)) == 0; bp = NEXT_FREE(bp))
    checkFreeNodes(bp);

}
开发者ID:aaiyer123,项目名称:malloc,代码行数:48,代码来源:mm.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ GET_ALPHA_BETA_FROM_QP函数代码示例发布时间:2022-05-30
下一篇:
C++ GETWORD函数代码示例发布时间: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