本文整理匯總了C++中GET_ALLOC函數的典型用法代碼示例。如果您正苦於以下問題:C++ GET_ALLOC函數的具體用法?C++ GET_ALLOC怎麽用?C++ GET_ALLOC使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GET_ALLOC函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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;
}
示例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;
}
示例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;
}
示例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')); */
}
示例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'));
}
示例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;
}
示例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'));
}
示例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;
}
示例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;
}
示例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
}
示例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));
}
}