本文整理汇总了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);
}
示例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
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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));
}
}
示例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;
}
示例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
}
示例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));
}
}
示例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));
}
示例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));
}
}
示例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);
}
}
示例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);
}