本文整理汇总了C++中coalesce函数的典型用法代码示例。如果您正苦于以下问题:C++ coalesce函数的具体用法?C++ coalesce怎么用?C++ coalesce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coalesce函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: freef
void freef(char *p)
{
printf("freef called with p=%p\n", (void *) p);
if(p!=0){
/* you write the code for the freef function here */
struct blockl *temp = (struct blockl *)p;
temp->tag = FREETAG;
char *temp2 = p;
temp2 += temp->size;
temp2 += (TAGSIZE*2);
struct blockr *temp3 = (struct blockr *)temp2;
temp3->tag = FREETAG;
struct blockr *temp4 = (struct blockr *)(p - TAGSIZE);
//temp4 -= 1;
if (temp4->tag == FREETAG) {
struct blockl *temp5 = (struct blockl *)(temp4 - temp4->size-(TAGSIZE));
coalesce(temp5, temp);
}
else{
enchain(temp);
}
temp2 += TAGSIZE;
struct blockl *temp6 = (struct blockl *)temp2;
if (temp6->tag == FREETAG){
unchain(temp6);
coalesce(temp, temp6);
}
}
}
开发者ID:Jyang772,项目名称:cs240,代码行数:29,代码来源:test.c
示例2: main
int main() {
int *p1, *p2;
printf("initial allocation\n");
initmemory(56);
printallocation();
printf("malloc 20\n");
p1 = (int *)myalloc(20);
printresult(p1);
printf("malloc 10\n");
p2 = (int *)myalloc(10);
printresult(p2);
printf("free (malloc 20)\n");
myfree(p1); p1 = NULL;
printallocation();
printf("malloc 4\n");
p1 = (int *)myalloc(4);
printresult(p1);
printf("free (malloc 10)\n");
myfree(p2); p2 = NULL;
printallocation();
printf("malloc 30: should fail\n");
// this will fail because we need a block of at least 40
p2 = (int *)myalloc(30);
printresult(p2);
printf("coalesce\n");
coalesce();
printallocation();
printf("malloc 30 \n"); // now this succeeds
p2 = (int *) myalloc(30);
printresult(p2);
printf("free everything\n");
myfree(p1); p1 = NULL;
myfree(p2); p2 = NULL;
printallocation();
printf("malloc 56: should fail\n");
// this will fail
p1 = (int *)myalloc(56);
printresult(p1);
printf("coalesce\n");
coalesce();
printallocation();
printf("malloc 56\n");
p1 = (int *)myalloc(56);
printresult(p1);
}
开发者ID:dlee37,项目名称:Computer-Systems,代码行数:58,代码来源:hw6test.c
示例3: coalesceBlocks
/**
* @brief Coalesce the free list into larger blocks.
* @param prev The previous block in the free list.
* @param current The block to coalesce.
* @param next The next block in the free list.
*/
static void coalesceBlocks(long *prev, long *current, long *next)
{
if (next != NULL) {
coalesce(current, next);
}
if (prev != NULL) {
coalesce(prev, current);
}
return;
}
开发者ID:rax85,项目名称:LinuxPthreadExtensions,代码行数:18,代码来源:mempool.c
示例4: mm_free
void mm_free(void *ptr) {
if (ptr != NULL) {
struct metadata *curr = get_block_ptr(ptr);
curr->free = 1;
if (curr->prev && curr->prev->free) {
curr = coalesce(curr->prev);
}
if (curr->next && curr->next->free) {
coalesce(curr);
}
}
}
开发者ID:jgao23,项目名称:operating_systems,代码行数:12,代码来源:mm_alloc.c
示例5: EXPECT_CALL
/**
* @param data full multipart content
* @param filesize sum of all parts
* @param parts number of parts
*/
void RFC1867Base::testSimple(unique_ptr<IOBuf> data,
size_t fileSize,
size_t splitSize,
size_t parts) {
size_t fileLength = 0;
IOBufQueue parsedData{IOBufQueue::cacheChainLength()};
EXPECT_CALL(callback_, onFieldStartImpl(_, _, _, _))
.Times(parts)
.WillRepeatedly(Return(0));
EXPECT_CALL(callback_, onFieldData(_, _))
.WillRepeatedly(Invoke([&] (std::shared_ptr<IOBuf> data, uint64_t) {
fileLength += data->computeChainDataLength();
parsedData.append(data->clone());
return 0;
}));
EXPECT_CALL(callback_, onFieldEnd(true, _))
.Times(parts)
.WillRepeatedly(Return());
parse(data->clone(), splitSize);
auto parsedDataBuf = parsedData.move();
if (fileLength > 0) {
// isChained() called from coalesce below asserts if no data has
// been added
parsedDataBuf->coalesce();
}
CHECK_EQ(fileLength, fileSize);
}
开发者ID:facebook,项目名称:proxygen,代码行数:32,代码来源:RFC1867Test.cpp
示例6: PUT
/**********************************************************
* extend_heap
* Extend the heap by "words" words, maintaining alignment
* requirements of course. Free the former epilogue block
* and reallocate its new header
**********************************************************/
void *extend_heap(size_t words)
{
char *bp;
size_t size;
/* Allocate an even number of words to maintain alignments */
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
/* Place at top of free list */
add_to_free_list(bp);
printf("add_to_free being called in extend()\n");
printf("extend - bp: %p\n", bp);
printf("extend - addr of prev: %p\n", PREV_FR_BP(bp));
printf("extend - addr of next: %p\n", NEXT_FR_BP(bp));
/* Coalesce if the previous block was free */
return coalesce(bp);
}
开发者ID:kan-o-ash,项目名称:Computer-Systems-Programming,代码行数:32,代码来源:mm.c
示例7: place
void place(char *bp, size_t size)
//allocate to block and update free list,split block if necessary
//place called after find_fit in MALLOC
//size is block including header and footer
{
ASSERT(GETALLOC(HDRP(bp)) == 0) ;
ASSERT(size <= GETSIZE(HDRP(bp))) ;
ASSERT(size % ALIGNMENT == 0) ;
//bp is empty block
size_t bSize = GETSIZE(HDRP(bp)) ;
if(bSize - size < MINBLOCKSIZE)
{
FL_remove(bp) ;
PUT(HDRP(bp), PACK(bSize, 1)) ;
PUT(FTRP(bp), PACK(bSize, 1)) ;
//change header and footer alloc bit
}
else if(bSize - size >= MINBLOCKSIZE)
{
ASSERT((bSize-size) % ALIGNMENT == 0) ;
// check if new block size will mess up alignment
FL_remove(bp) ;//remove bp from free list
PUT(HDRP(bp) ,PACK(size, 1)) ;
PUT(FTRP(bp), PACK(size,1)) ;
ASSERT(isValidBlock(bp)) ;
bp = NEXT_BLKP(bp) ;
PUT(HDRP(bp) ,PACK(bSize - size, 0));
PUT(FTRP(bp), PACK(bSize-size, 0)) ;
ASSERT(isValidBlock(bp)) ;
coalesce(bp) ; //insert split block back to free list
}
dmm_checkheap(278) ; //CHECKHEAP!!!!!!!!!!!!!!!!!!!!!
return ;
}
开发者ID:sam1323123,项目名称:Projects,代码行数:35,代码来源:mem_exp.c
示例8: allocate
/**
* allocate - Place block, i.e. write header and footer.
*/
static void allocate(void *bp, size_t adjusted_size)
{
size_t csize = GET_THISSIZE(bp);
size_t is_prev_alloc = GET_PREVALLOC(bp);
TRACE(">>>Entering allocate(bp=0x%X, adjusted_size=%u)\n", (unsigned int)bp, adjusted_size);
/* We will always need to remove tshi block from the free list */
remove_from_list(bp, calc_list_index(csize));
/* See if there's room to split this block into two */
if ((csize - adjusted_size) >= (MIN_SIZE)) {
PUTW(GET_BLOCKHDR(bp), PACK(adjusted_size, THISALLOC | is_prev_alloc));
PUTW(GET_BLOCKFTR(bp), PACK(adjusted_size, THISALLOC | is_prev_alloc));
/* Using the new header info, mark the newly created block as free */
bp = GET_NEXTBLOCK(bp);
PUTW(GET_BLOCKHDR(bp), PACK(csize - adjusted_size, PREVALLOC));
PUTW(GET_BLOCKFTR(bp), PACK(csize - adjusted_size, PREVALLOC));
/* And add it to the appropriate free list */
coalesce(bp);
}
else {/* If there's not room to create split the block, just extend the
amount to allocated */
PUTW(GET_BLOCKHDR(bp), PACK(csize, THISALLOC | is_prev_alloc));
PUTW(GET_BLOCKFTR(bp), PACK(csize, THISALLOC | is_prev_alloc));
/* Make sure the next block's header has the prevalloc field marked */
bp = GET_BLOCKHDR(GET_NEXTBLOCK(bp));
PUTW(bp, GETW(bp) | PREVALLOC);
}
TRACE("<<<---Leaving allocate()\n");
}
开发者ID:val-litvak,项目名称:malloclab,代码行数:37,代码来源:mm.c
示例9: MAX
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;
size = MAX(size, BSIZE);
/* call for more memory space */
if ((int)(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 bp with next and previous blocks */
return coalesce(bp);
}
开发者ID:ktlwik,项目名称:System-Programming,代码行数:33,代码来源:malloclab.c
示例10: free_single_page
void free_single_page(region r, struct page *p)
/* Assumes freepages_lock held */
{
#ifndef NMEMDEBUG
ASSERT_INUSE(p, r);
set_page_region(PAGENB(p), FREEPAGE);
#endif
// fprintf(stderr, "## free_single_page: p=%p, p->pagecount=%d\n", p, p->pagecount);
// assert(p->pagecount > 0);
assert(p->pagecount == 1);
/* Don't keep too many single pages (a small fraction of total
allocated pages) */
if (single_page_count > PAGE_GROUP_SIZE * 2)
{
// quarl 2006-05-13: we now enforce the invariant that p->pagecount is
// correct, so it should already be 1 at this point.
// p->pagecount = 1; // XXX
coalesce(p);
}
else
{
p->next = single_pages;
single_pages = p;
single_page_count++;
}
}
开发者ID:Dastrius,项目名称:oink-stack,代码行数:27,代码来源:pages.c
示例11: free
/*
* free - Frees the block and coalesces
* (implementation issue: coalescing)
*
*/
void free(void *bp)
{
size_t size;
size_t prev_alloc;
size_t temp_value;
dbg1("[IN ] : free()\n");
if (!bp) {
dbg1("[OUT] : free() - NULL pointer\n");
return;
}
if (!mm_initialized)
mm_init();
size = GET_SIZE(HDRP(bp));
prev_alloc = GET_PREV_ALLOC(HDRP(bp));
/* update header and footer pointers of this block */
PUT(HDRP(bp), PACK(size, prev_alloc));
PUT(FTRP(bp), PACK(size, prev_alloc));
/* tell next block that this block is now free */
temp_value = GET(HDRP(NEXT_BLKP(bp))) & ~0x2;
PUT(HDRP(NEXT_BLKP(bp)), temp_value);
coalesce(bp);
dbg1("[OUT] : free()\n");
}
开发者ID:447327642,项目名称:CSAPP2e,代码行数:36,代码来源:mm-seglist.c
示例12: git_blame__like_git
void git_blame__like_git(git_blame *blame, uint32_t opt)
{
while (true) {
git_blame__entry *ent;
git_blame__origin *suspect = NULL;
/* Find a suspect to break down */
for (ent = blame->ent; !suspect && ent; ent = ent->next)
if (!ent->guilty)
suspect = ent->suspect;
if (!suspect)
return; /* all done */
/* We'll use this suspect later in the loop, so hold on to it for now. */
origin_incref(suspect);
pass_blame(blame, suspect, opt);
/* Take responsibility for the remaining entries */
for (ent = blame->ent; ent; ent = ent->next) {
if (same_suspect(ent->suspect, suspect)) {
ent->guilty = true;
ent->is_boundary = !git_oid_cmp(
git_commit_id(suspect->commit),
&blame->options.oldest_commit);
}
}
origin_decref(suspect);
}
coalesce(blame);
}
开发者ID:Darthholi,项目名称:WDX_GitCommander,代码行数:31,代码来源:blame_git.c
示例13: place
//Called by mm_alloc, places
void place (void *bp, size_t asize){
size_t size = GET_SIZE(HDRP(bp));
size_t frag = size - asize;
//internal fragment
if (frag < MINBLKSIZE){
PUT(HDRP(bp), PACK(size, 1));
PUT(FTRP(bp), PACK(size, 1));
delete_free_block(bp); //remove allocated block from free list
// fwdPointers(bp, frag); //Reassigns pointers
}
//external fragment
else{
PUT(HDRP(bp), PACK(asize, 1));
PUT(FTRP(bp), PACK(asize, 1));
//fwdPointers(bp, frag);
delete_free_block(bp);
bp = NEXT_BLKP(bp); //Move pointer to next block
PUT(HDRP(bp), PACK(frag, 0));
PUT(FTRP(bp), PACK(frag, 0));
coalesce(bp);
// moveStart(bp);
}
}
开发者ID:bremerle3,项目名称:cse361,代码行数:26,代码来源:mm_submittable.c
示例14: list_free
int list_free(void* ptr)
{
header_t* hptr = (header_t*) (ptr - sizeof(header_t));
#ifdef DEBUG
printf("\n------------------------------MEM-FREE--------------------------------\n");
printf("Entering Mem_Free with PTR: %p, HPTR: %p, Magic: %d, Size: %d\n", ptr, hptr, hptr->magic, hptr->size);
#endif
if(hptr->magic != MAGIC) //Check if its the valid pointer
return (-1);
if(head == NULL)
{
#ifdef DEBUG
printf("NULL header - nothing to coalesce\n"); //Nothing to coalesce
#endif
head = (node_t*) hptr;
head->size = hptr->size;
head->next= NULL;
return 0;
}
//Attach the new incoming ptr as the new head
node_t* temp = head;
head = (node_t*) hptr;
head->size = hptr->size;
head->next = temp;
//Calling Coalescer
coalesce();
return 0;
}
开发者ID:vinaygangadhar,项目名称:cs537_projects,代码行数:34,代码来源:helper.c
示例15: freeRegion
void freeRegion(void *r) {
if (r != 0) {
BlockPrefix_t *p = regionToPrefix(r); /* convert to block */
p->allocated = 0; /* mark as free */
coalesce(p);
}
}
开发者ID:2017-fall-os,项目名称:2017-fall-malloc-lab-kvillanueva,代码行数:7,代码来源:myAllocatorNextFit.c
示例16: place
static void place(void *bp, size_t asize){
size_t csize = HDRSIZE(bp);
if ((csize - asize) >= BSIZE) {
PUT(HDRP(bp), PACK(asize, 1));
PUT(FTRP(bp), PACK(asize, 1));
del(bp); // deleting current block
bp = NEXT_BLKP(bp);
PUT(HDRP(bp), PACK(csize-asize, 0));
PUT(FTRP(bp), PACK(csize-asize, 0));
coalesce(bp);
}
else {
PUT(HDRP(bp), PACK(csize, 1));
PUT(FTRP(bp), PACK(csize, 1));
del(bp);
}
}
开发者ID:ktlwik,项目名称:System-Programming,代码行数:35,代码来源:malloclab.c
示例17: mm_free
/*
* mm_free - Freeing a block does nothing.
*/
void mm_free(void *ptr) //LIFO policy of adding to free list
{
blockHdr *bp = ptr-SIZE_T_SIZE;
blockHdr *nu_bp = coalesce((size_t *) bp);
nu_bp->size &= ~1;
}
开发者ID:morlowsk,项目名称:Work,代码行数:10,代码来源:mm.c
示例18: free
/*
* free
*/
void free (void *ptr) {
if (ptr == NULL) {
return;
}
block_mark(get_header(ptr), 0);
coalesce(ptr);
}
开发者ID:prajwal-y,项目名称:CMU_15-513,代码行数:10,代码来源:mm-implicit.c
示例19: mm_free
/*
* mm_free - Free a block by adding it to the appropriate list and coalescing
* it.
*/
void mm_free(void *ptr)
{
size_t size = GET_SIZE(HEAD(ptr)); /* Size of block */
/* Unset the reallocation tag on the next block */
UNSET_TAG(HEAD(NEXT(ptr)));
/* Adjust the allocation status in boundary tags */
PUT(HEAD(ptr), PACK(size, 0));
PUT(FOOT(ptr), PACK(size, 0));
/* Insert new block into appropriate list */
insert_node(ptr, size);
/* Coalesce free block */
coalesce(ptr);
/*
// Check heap for consistency
line_count++;
if (CHECK && CHECK_FREE) {
mm_check('f', ptr, size);
}
*/
return;
}
开发者ID:bloveless,项目名称:malloclab,代码行数:32,代码来源:mm_ref0.c
示例20: printf
/**********************************************************
* extend_heap
* Extend the heap by "words" words, maintaining alignment
* requirements of course. Free the former epilogue block
* and reallocate its new header
**********************************************************/
void *extend_heap(size_t words)
{
#if DEBUG >= 3
printf(" %zu words ", words);
#endif
char *bp;
size_t size;
/* Allocate an even number of words to maintain alignments */
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
getNext(bp) = NULL;
getPrev(bp) = NULL;
/* Coalesce if the previous block was free */
return coalesce(bp);
}
开发者ID:bkashyap,项目名称:ece454,代码行数:32,代码来源:mm.c
注:本文中的coalesce函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论