本文整理汇总了C++中HDRP函数的典型用法代码示例。如果您正苦于以下问题:C++ HDRP函数的具体用法?C++ HDRP怎么用?C++ HDRP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HDRP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: place
static void place(void *bp, size_t size){
size_t totalsize = GET_SIZE(HDRP(bp));
if((totalsize - size) >= OVERHEAD){
PUT(HDRP(bp), PACK(size, 1));
PUT(FTRP(bp), PACK(size, 1));
mm_remove(bp);
bp = NEXT_BLKP(bp);
PUT(HDRP(bp), PACK(totalsize - size, 0));
PUT(FTRP(bp), PACK(totalsize - size, 0));
coalesce(bp);
}
else{
PUT(HDRP(bp), PACK(totalsize, 1));
PUT(FTRP(bp), PACK(totalsize, 1));
mm_remove(bp);
}
}
示例2: 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));
}
示例3: 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));
}
}
示例4: GET_ALLOC
/*
* find_fit - Find a fit for a block with asize bytes
*/
static void *find_fit(size_t asize)
{
/* First-fit search */
void *bp;
/* Free list is empty */
if (free_list_header == NULL) {
return NULL;
}
/* Stop at prologue, while prologue is allocted */
for (bp = free_list_header;
GET_ALLOC(HDRP(bp)) == 0; bp = GET_SUCC_FREE_BLKP(bp)) {
if (asize <= GET_SIZE(HDRP(bp))) {
return bp;
}
}
return NULL; /* No fit */
}
示例5: 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));
}
}
示例6: PUT
/*
* extend_heap - Extend heap with free block and return its block pointer
*/
static void *extend_heap(size_t words) /* TODO */
{
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;
/* 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);
}
示例7: 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);
}
示例8: 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);
}
}
示例9: PUT
static void *extend_heap(size_t words)
{
char *ptr;
size_t size;
/* Allocate an even number of words to maintain alignment */
size = (words % 2) ? (words+1) * SWORD : words * SWORD;
if ((long)(ptr = mem_sbrk(size)) == -1)
return NULL;
/* Initialize free block header/footer and the epilogue header */
PUT(HDRP(ptr), PACK(size, 0)); /* Free block header */
PUT(FTRP(ptr), PACK(size, 0)); /* Free block footer */
PUT(HDRP(NEXT_BLKP(ptr)), PACK(0, 1)); /* New epilogue header */
/* Coalesce if the previous block was free */
printf("Before coalesce\n");
return coalesce(ptr);
}
示例10: 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')); */
}
示例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: Exam_list
static void Exam_list(int asize){
void *bp;
int csize;
if(!asize){
printf("\n-------mem list----------\n");
for(bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)){
printf("block %x:%x of realsize:%d %d \n",bp,bp+GET_SIZE(HDRP(bp)),GET_SIZE(HDRP(bp)),GET_ALLOC(HDRP(bp)));
}
}else{
printf("\n------mem size[%d]----------\n",asize);
for(bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)){
csize = GET_SIZE(HDRP(bp));
if(!GET_ALLOC(HDRP(bp))){
if(csize<asize)printf("%d \t",csize);
else printf("\033[42;30m%d\033[0m \t",csize);
}
}
}
}
示例13: 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'));
}
示例14: mm_init
/*
* malloc
*/
void *malloc (size_t size) {
size_t asize; /* Adjusted block size */
size_t extendsize; /* Amount to extend heap if no fit */
char *bp;
if (heap_listp == 0){
mm_init();
}
/* Ignore spurious requests */
if (size == 0)
return NULL;
asize = ALIGN(size + 4); /* the overhead is payload + header(4 byte) + padding(optional) */
asize = MAX(asize, MINSIZE * WSIZE); /* require minimum size */
/* Search the free list for a fit */
if ((bp = find_fit(asize)) != NULL) {
#ifdef DEBUG
printf("malloc: before alloc.\n");
mm_checkheap(1);
#endif
place(bp, asize);
#ifdef DEBUG
printf("malloc: after alloc.\n");
mm_checkheap(1);
printf("\n\n");
#endif
return bp;
}
/* No fit found. Get more memory and place the block */
int tail_free = 0; // the free space we have in the tail of heap
if (heap_tailp && !GET_ALLOC(HDRP(heap_tailp))) {
tail_free = GET_SIZE(HDRP(heap_tailp));
}
extendsize = MAX(asize - tail_free,CHUNKSIZE);
bp = extend_heap(extendsize/WSIZE);
if (bp == NULL)
return NULL;
place(bp, asize);
return bp;
}
示例15: printBlock
/*
* printBlock - prentar ut staka blokk
*/
void printBlock(void *bp) {
if(GET_ALLOC(HDRP(bp)))
printf("%p | hdr: %p | ftr: %p | Size %d | Alloc: %d\n" ,
bp, HDRP(bp), FTRP(bp), GET_SIZE(HDRP(bp)), GET_ALLOC(HDRP(bp)));
else
printf("%p | hdrp %p | ftr: %p | prevfre: %p | nextfre: %p | Size: %d | Alloc: %d\n",
bp, HDRP(bp), FTRP(bp), NEXT_FREE_BLKP(bp), PREV_FREE_BLKP(bp),
GET_SIZE(HDRP(bp)), GET_ALLOC(HDRP(bp)));
}