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


C++ NEXT_BLKP函数代码示例

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


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

示例1: mm_free

void mm_free(void *bp)
{
        size_t size;

        int prev_alloc = GET_ALLOC_PREV(HDRP(bp));
        size = GET_SIZE(HDRP(bp));
        PUT(HDRP(bp), PACK(size, prev_alloc));
        PUT(FTRP(bp), PACK(size, prev_alloc));

        char *next_block = NEXT_BLKP(bp);
        int next_alloc = GET_ALLOC(HDRP(next_block));
        size = GET_SIZE(HDRP(next_block));
        PUT(HDRP(next_block), PACK(size, next_alloc));
        if (!next_alloc)
                PUT(FTRP(next_block), PACK(size, next_alloc));

        coalesce(bp);
}
开发者ID:lirenjie95,项目名称:CSAPP,代码行数:18,代码来源:9-18.c

示例2: PUT

/* $begin mmextendheap */
static void *extend_heap(size_t words)
{
    char *bp;
    size_t size;
    
    /* Allocate an even number of words to maintain alignment */
    size = (words % 2) ? (words+1) * WSIZE : words * WSIZE; //line:vm:mm:beginextend
    if ((long)(bp = mem_sbrk(size)) == -1)
        return NULL;                                        //line:vm:mm:endextend
    
    /* Initialize free block header/footer and the epilogue header */
    PUT(HDRP(bp), PACK(size, 0));         /* Free block header */   //line:vm:mm:freeblockhdr
    PUT(FTRP(bp), PACK(size, 0));         /* Free block footer */   //line:vm:mm:freeblockftr
    PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); /* New epilogue header */ //line:vm:mm:newepihdr
    
    /* Coalesce if the previous block was free */
    return coalesce(bp);                                          //line:vm:mm:returnblock
}
开发者ID:liopei19nn,项目名称:15213_LIP,代码行数:19,代码来源:mm.c

示例3: extend_heap

//Extend the heap in case when the heap size is not sufficient to hold the block 
static void* extend_heap(size_t words){
    char *bp;
    size_t size;

    size = (words % 2) ? (words + 1) * WSIZE : words * WSIZE;                            

    size = MAX(size,OVERHEAD);

    if((int)(bp = mem_sbrk(size)) == -1){                                               
        return NULL;
    }

    PUT(HDRP(bp), PACK(size, 0));         
    PUT(FTRP(bp), PACK(size, 0));         
    PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); 
  
    return coalesce(bp);                  
}
开发者ID:bremerle3,项目名称:cse361,代码行数:19,代码来源:mm_70.c

示例4: 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

示例5: PUT

/*
 * extend_heap - Extend heap with free block and return its block pointer
 */
static void *extend_heap(size_t words)
{
    void *bp;
    size_t size;
	
    /* Allocate an even number of words to maintain alignment */
    size = (words % 2) ? (words+1) * WSIZE : words * WSIZE;
    if ((bp = mem_sbrk(size)) == (void *) -1)
        return NULL;
    
    /* Initialize free block header/footer and the epilogue header */
    PUT(HDRP(bp), PACK(size, 0));         /* free block header */
    PUT(FTRP(bp), PACK(size, 0));         /* free block footer */
    PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); /* new epilogue header */
    
    /* Coalesce if the previous block was free */
    return coalesce(bp);
}
开发者ID:NguyenTrav,项目名称:mm-malloc,代码行数:21,代码来源:mm-implicit.c

示例6: PUT

//
// extend_heap - Extend heap with free block and return its block pointer
//
static void *extend_heap(size_t words) 
{
  char *bp;
  size_t size;

  // Allocate an even number of words to maintain alignment
  size = (words % 2) ? (words+1) * WSIZE : words * WSIZE;
  if ((long)(bp = mem_sbrk(size)) == -1)
    return NULL;

  // Initilalize free block header/footer and the epilogue header
  PUT(HDRP(bp), PACK(size, 0));		// Free block header
  PUT(FTRP(bp), PACK(size, 0));		// Free block footer
  PUT(HDRP(NEXT_BLKP(bp)), PACK(0,1));	// New epilogue header

  // Coalesce if the previous block was free
  return coalesce(bp);
}
开发者ID:kerns95,项目名称:malloc,代码行数:21,代码来源:mm.backup.c

示例7: 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

示例8: GET_ALLOC

/**********************************************************
 * 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)
{
	//printf("IN COALESCE\n");
	//printf("coalescing block ptr %p\n",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));
	//printf("sizeof size_t %08p\n",sizeof(size_t));

	if (prev_alloc && next_alloc) {       /* Case 1 */
		//printf("case 1\n");
		add_to_free_list(bp);	//add to the free list
		//print_ptr(bp);
		return bp;
	}
	else if (prev_alloc && !next_alloc) { /* Case 2 */

		//printf("case 2\n");
		size += GET_SIZE(HDRP(NEXT_BLKP(bp)));

		remove_free_block(NEXT_BLKP(bp)); //remove the free block from the free list
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
		add_to_free_list(bp);
		return (bp);
	}
	else if (!prev_alloc && next_alloc) { /* Case 3 */
		//printf("case 3\n");
		size += GET_SIZE(HDRP(PREV_BLKP(bp)));

		remove_free_block(PREV_BLKP(bp));
		PUT(FTRP(bp), PACK(size, 0));
		PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
		add_to_free_list(PREV_BLKP(bp));
		//print_ptr(PREV_BLKP(bp));
		//print_ptr(bp);
		return (PREV_BLKP(bp));
	}
	else {            /* Case 4 */
		//printf("case 4\n");
		size += GET_SIZE(HDRP(PREV_BLKP(bp)))+GET_SIZE(FTRP(NEXT_BLKP(bp)));
		remove_free_block(PREV_BLKP(bp));
		remove_free_block(NEXT_BLKP(bp));
		PUT(HDRP(PREV_BLKP(bp)), PACK(size,0));
		PUT(FTRP(NEXT_BLKP(bp)), PACK(size,0));
		add_to_free_list(PREV_BLKP(bp));
		//print_ptr(bp);

		return (PREV_BLKP(bp));
	}
}
开发者ID:shareq2005,项目名称:Dynamic-Memory-Allocator,代码行数:59,代码来源:mm.c

示例9: 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){
        return bp;
    }

    else if (prev_alloc && !next_alloc){
        offlist(NEXT_BLKP(bp));

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

    else if (!prev_alloc && next_alloc){
        offlist(bp);

        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
	PUT(SUC(bp), GET(SUC(PREV_BLKP(bp))));
        PUT(FTRP(bp),PACK(size,0));
        PUT(HDRP(PREV_BLKP(bp)),PACK(size,0));
        bp = PREV_BLKP(bp);
    }

    else {
        offlist(bp);
        offlist(NEXT_BLKP(bp));

        size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(FTRP(NEXT_BLKP(bp)));
	PUT(SUC(NEXT_BLKP(bp)), GET(SUC(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:RayneZhang,项目名称:csapp-lab,代码行数:41,代码来源:mm.c

示例10: GET_SIZE

/* used in realloc */
static void *replace(void *bp, size_t asize)
{
    size_t csize = GET_SIZE(HDRP(bp));

    if((csize - asize) >= (2 * DSIZE))
    {
        //contain old block data
        PUT(HDRP(bp), PACK(asize, 1));
        PUT(FTRP(bp), PACK(asize, 1));

        void *p = NEXT_BLKP(bp);
        PUT(HDRP(p), PACK((csize - asize), 0));
        PUT(FTRP(p), PACK((csize - asize), 0));
    	add_free(p);
        return bp;
    }
    else return bp; //no action

}
开发者ID:YeXiaoRain,项目名称:ICS_LAB,代码行数:20,代码来源:exp_mm(显式链表).c

示例11: place

static void place(void *bp, size_t asize)
{
    size_t csize = GET_SIZE(HDRP(bp));

    if((csize - asize) >= (3*DSIZE))
    {
        PUT(HDRP(bp), PACK(asize, 1));
        PUT(FTRP(bp), PACK(asize , 1));
        bp = NEXT_BLKP(bp);
        PUT(HDRP(bp), PACK(csize-asize, 0));
        PUT(FTRP(bp), PACK(csize-asize, 0));
        add_to_group(bp);
    }
    else
    {
        PUT(HDRP(bp), PACK(csize, 1));
        PUT(FTRP(bp), PACK(csize, 1));
    }
}
开发者ID:drewmacmac,项目名称:old_class,代码行数:19,代码来源:mm.c

示例12: return

/*my helper functions*/
static void *extend_heap(size_t words)
{
    void *bp;
    size_t size;
    /* Allocate an even number of words to maintain alignment. */
    size = (words % 2) ? (words + 1) * WSIZE : words * WSIZE;
    if ((bp = mem_sbrk(size)) == (void *)-1)
    {
	return (NULL);
    }
    /* Initialize free block header/footer and the epilogue header. */
    PUT(HDRP(bp), PACK(size, 0));         /* Free block header */
    PUT(NEXT(bp), 0);  /*next address is null*/
    PUT(PREV(bp), 0);  /*prev address is null*/
    PUT(FTRP(bp), PACK(size, 0));         /* Free block footer */
    PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); /* New epilogue header */
    /* Coalesce if the previous block was free. */
    return (coalesce(bp));
}
开发者ID:dukelv,项目名称:csci033,代码行数:20,代码来源:mm.c

示例13: place

//将空闲位标志为分配位
static void place(void *bp, size_t asize)
{
	size_t csize=GET_SIZE(HDRP(bp));

	//如果一个块儿不够
	if((csize-asize) >= (2*DSIZE)){

		PUT(HDRP(bp), PACK(asize, 1));
		PUT(FTRP(bp), PACK(asize, 1));
		bp=NEXT_BLKP(bp);

		//占用下一个块儿一些空间
		PUT( HDRP(bp), PACK(csize-asize, 0) );	
		PUT( FTRP(bp), PACK(csize-asize, 0) );	
	}else{
		PUT(HDRP(bp), PACK(csize, 1));
		PUT(FTRP(bp), PACK(csize, 1));
	}
}
开发者ID:scentsoul,项目名称:the_practice,代码行数:20,代码来源:mm_malloc.c

示例14: place

/* Decides whether we can split the block, and if so performs the split
by computing leftover block space, deleting shortened allocated block, 
and then labeling split free block and coalescing. 
Otherwise, just resets size and allocation tags of block and deletes
it from free list. */
static void place(void *bp, size_t asize) {
    size_t csize = GET_SIZE(HDRP(bp));

    if ((csize - asize) >= MIN_BLOCK_SIZE) {
        PUT(HDRP(bp), PACK(asize, 1));
        PUT(FTRP(bp), PACK(asize, 1));
        deleteBlk(bp);
        bp = NEXT_BLKP(bp);
        PUT(HDRP(bp), PACK(csize-asize, 0));
        PUT(FTRP(bp), PACK(csize-asize, 0));
        coalesce(bp);
    }
    /* Not enoough room to split, simple allocation and free list deletion */
    else {
        PUT(HDRP(bp), PACK(csize, 1));
        PUT(FTRP(bp), PACK(csize, 1));
        deleteBlk(bp);
    }
}
开发者ID:NikhilCMU,项目名称:Coding_Projects,代码行数:24,代码来源:mm.c

示例15: PUT

/* Extends the heap by asking for more space, and reassigning pointers
accordingly. */
static void *extend_heap(size_t words) {
    char *bp;
    size_t size;

    size = (words % 2) ? (words+1) * WSIZE : words * WSIZE;

    if (size < MIN_BLOCK_SIZE) {
        size = MIN_BLOCK_SIZE;
    }
    if ((long)(bp = mem_sbrk(size)) == -1)
        return NULL;

    /* Initialize free block header/footer and the epilogue header */
    PUT(HDRP(bp), PACK(size, 0)); /* Free block header */
    PUT(FTRP(bp), PACK(size, 0)); /* Free block footer */
    PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1));

    return coalesce(bp);
}
开发者ID:NikhilCMU,项目名称:Coding_Projects,代码行数:21,代码来源:mm.c


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