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


C++ FTRP函数代码示例

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


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

示例1: 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 */
        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);
    }
    /* $end mmfree */
#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
    /* $begin mmfree */
    return bp;
}
开发者ID:liopei19nn,项目名称:15213_LIP,代码行数:41,代码来源:mm.c

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

示例3: 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(FTRP(NEXT_BLKP(bp)));
  size_t size = GET_SIZE(HDRP(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 {
    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:kerns95,项目名称:malloc,代码行数:34,代码来源:mm.backup.c

示例4: 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));
	
	if (prev_alloc && next_alloc) {
		CL_tack(&free_list, bp); // case 1 neighbours = 1  add a return?
	}
	
	else if (prev_alloc && !next_alloc) { // case 2 next is free
		CL_unlink(next);
		CL_tack(&free_list, bp);
		
		size += GET_SIZE(HDRP(next));
		PUT(HDRP(bp), PACK(size, 0));
		PUT(FTRP(bp), PACK(size, 0));
	}
	
	else if (!prev_alloc && next_alloc) { // case 3 prev is free
		size += GET_SIZE(HDRP(prev));
		PUT(FTRP(bp), PACK(size, 0));
		PUT(HDRP(prev), PACK(size, 0));
		bp = prev;
	}

	else { // both next and prev free
		size += GET_SIZE(HDRP(prev)) + GET_SIZE(FTRP(next));
		CL_unlink(next);
		PUT(HDRP(prev), PACK(size, 0 ));
		PUT(FTRP(next), PACK(size, 0));
		bp = prev;
	}
	
	return bp;
}
开发者ID:Boraz,项目名称:CSCI-2400,代码行数:42,代码来源:mm.c

示例5: mm_free

/* 
 * Requires:
 *   "bp" is either the address of an allocated block or NULL.
 *
 * Effects:
 *   Free a block.
 */
void 
mm_free(void *bp)
{
  size_t size;
  /* Ignore spurious requests. */
  if (bp == NULL)
    return;
  /* Free and coalesce the block. */
  size = GET_SIZE(HDRP(bp));
  PUT(HDRP(bp), PACK(size, 0));
  PUT(FTRP(bp), PACK(size, 0));
  coalesce(bp);
}
开发者ID:nik-6947,项目名称:malloc,代码行数:20,代码来源:mm.c

示例6: mm_free

/*
 * mm_free - Freeing a block does nothing.
 *
 * Role : The mm_free routine frees the block pointed to by ptr
 *
 * Return value : returns nothing
 */
void mm_free(void *ptr)
{
    size_t size = GET_SIZE(HDRP(ptr));
 
    REMOVE_RATAG(HDRP(NEXT_BLKP(ptr)));
    PUT(HDRP(ptr), PACK(size, 0));
    PUT(FTRP(ptr), PACK(size, 0));
    
    insert_node(ptr, size);
    coalesce(ptr);
    
    return;
}
开发者ID:gowtamvamsi,项目名称:Malloc-Lab,代码行数:20,代码来源:mm.c

示例7: add_to_group

static void add_to_group(char* bp) {
    int size = GET_SIZE(HDRP(bp));
    int group = get_group(size);
    void* heap_listp_new = heap_listp - (GROUPSIZE + (2*WSIZE));
    int** grpp = heap_listp_new + (group * WSIZE);    
    if (*grpp) {
        int* tmpptr = *grpp;
        PUT(HDRP(bp) + 4, (int)tmpptr);
        PUT(FTRP(bp) + 4, (int)tmpptr);
    }    
    //printf("group: %d", group);
    PUTPTR(grpp, bp);
}
开发者ID:drewmacmac,项目名称:old_class,代码行数:13,代码来源:mm_backup_11_21.c

示例8: GET_ALLOC

/* Looks to the right and to the left to combine with nearby free blocks
in order to minimize fragmentation. */
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));

    /* Coalesce with block to the right */
    if (prev_alloc && !next_alloc) {
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        /* Now remove coalesced block to make room for actual coalesce */
        deleteBlk(NEXT_BLKP(bp));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
    }
    /* Coalesce with block to the left */
    else if (!prev_alloc && next_alloc) {
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        bp = PREV_BLKP(bp);
        deleteBlk(bp); // Delete previous blck to make room
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
    }
    /* Coalesce with both left and right blocks */
    else if (!prev_alloc && !next_alloc) {
        size += GET_SIZE(HDRP(PREV_BLKP(bp))) +
                GET_SIZE(HDRP(NEXT_BLKP(bp)));
        /* Deletes next and previous blocks to make more room,
        then reassigns bp to reflect coalescing */
        deleteBlk(PREV_BLKP(bp));
        deleteBlk(NEXT_BLKP(bp));
        bp = PREV_BLKP(bp);
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
    }

    /* Insert newly freed block at the front of free list */
    reinsert(bp);

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

示例9: place

/* place - 
 * Places the requested block at the beginning of the freeblock, and splitting * only if the size of the remainder block would equal or exceed the minimum  * block size */
static void place(void *bp, size_t asize) {
    size_t csize = GET_SIZE(HDRP(bp));   
    size_t remainder = csize - asize;

    if (remainder >= (MINSIZE * WSIZE)) {          
        remove_from_list(find_list(GET_SIZE(HDRP(bp))), bp);
        SET_SIZE(HDRP(bp), asize);
        SET_ALLOC(HDRP(bp));
        bp = NEXT_BLKP(bp);
        SET_SIZE(HDRP(bp), remainder);
        SET_SIZE(FTRP(bp), remainder);
        UNSET_ALLOC(HDRP(bp));
        UNSET_ALLOC(FTRP(bp));        
        SET_TAG(HDRP(bp));
        SET_TAG(FTRP(bp));        
        add_to_list(find_list(GET_SIZE(HDRP(bp))), bp);
    }else { 
        remove_from_list(find_list(GET_SIZE(HDRP(bp))), bp);
        SET_ALLOC(HDRP(bp));
        SET_TAG(HDRP(NEXT_BLKP(bp)));
    }
}
开发者ID:csukuangfj,项目名称:15-213-Introduction-to-Computer-Systems,代码行数:24,代码来源:mm.c

示例10: print_free_block

/**
 * print_free_block - Print the contents of the given free block, including 
 *                    the pointers
 * @param bp Block to be printed
 */
static void print_free_block(void *bp) 
{
    size_t hsize = -1, halloc, fsize, falloc;

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

    if (hsize == 0) {
        dbg_printf("%p: EOL\n", bp);
        return;
    }
}
开发者ID:AceYuRanger,项目名称:MallocLab,代码行数:27,代码来源:mm.c

示例11: mm_free

/*
 * frees a block of memory, enabling it to be reused later
 * arguments: ptr: the allocated block to free
 * returns: nothing
 */
void mm_free(void *ptr) {
    size_t size;
    /* Ignore spurious requests. */
    if (ptr == NULL)
    {
	return;
    }
    /* Free and coalesce the block. */
    size = GET_SIZE(HDRP(ptr));
    PUT(HDRP(ptr), PACK(size, 0));
    PUT(FTRP(ptr), PACK(size, 0));
    coalesce(ptr);
}
开发者ID:dukelv,项目名称:csci033,代码行数:18,代码来源:mm.c

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

示例13: GET_SIZE

/* $begin mmplace-proto */
static void *place(void *bp, size_t asize)
// $end mmplace-proto 
{
    size_t csize = GET_SIZE(HDRP(bp));
	void *alloBlock = bp;

    if ((csize - asize) >= (DSIZE + OVERHEAD)) { 
		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));
		// setjum free blokkina sem kom út úr splitti í free lista
		insert_block(bp);
    }
    else {
        PUT(HDRP(bp), PACK(csize, 1));
        PUT(FTRP(bp), PACK(csize, 1));
    }
	// skilum pointer á allocated blokkina
	return alloBlock;
}
开发者ID:olikari,项目名称:malloclab,代码行数:23,代码来源:mm.c

示例14: ALIGN

/*
 * extend_heap - Extends the heap when the desired memory is not available
 *
 */
static void *extend_heap(size_t words) {
    char *bp;
    size_t size=words*WSIZE;
    size = ALIGN(size+SIZE_T_SIZE); /* Set the size of the block to follow double word Allignment */
 \
    if ((int)(bp = mem_sbrk(size)) == -1)
        return NULL;

    PUT(HDRP(bp), PACK(size, 0)); /* Sets the Header of the Block */
    PUT(FTRP(bp), PACK(size, 0)); /* Sets the Footer of the Block */
    PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); /* Epilogue has to be created at the end */
    return coalesce(bp); /* Coalescing the Free blocks (Immediate Coalescing) */
}
开发者ID:punit9462,项目名称:IT-Projects,代码行数:17,代码来源:mm.c

示例15: place

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

    offlist(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));
        
        PUT(bp, endfree);
        PUT(SUC(bp), NULL);
        if (endfree)
            PUT(SUC(endfree), bp);
        endfree = bp;
    }
    else{
        PUT(HDRP(bp),PACK(csize,1));
        PUT(FTRP(bp),PACK(csize,1));
    }
}
开发者ID:RayneZhang,项目名称:csapp-lab,代码行数:22,代码来源:mm.c


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