• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PACK函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: MSGPACK_PACKET_INIT

void Client::sendPlayerPos()
{
	LocalPlayer *myplayer = m_env.getLocalPlayer();
	if(myplayer == NULL)
		return;

	// Save bandwidth by only updating position when something changed
	if(myplayer->last_position == myplayer->getPosition() &&
			myplayer->last_speed == myplayer->getSpeed() &&
			myplayer->last_pitch == myplayer->getPitch() &&
			myplayer->last_yaw == myplayer->getYaw() &&
			myplayer->last_keyPressed == myplayer->keyPressed)
		return;

	myplayer->last_position = myplayer->getPosition();
	myplayer->last_speed = myplayer->getSpeed();
	myplayer->last_pitch = myplayer->getPitch();
	myplayer->last_yaw = myplayer->getYaw();
	myplayer->last_keyPressed = myplayer->keyPressed;

	u16 our_peer_id;
	{
		//MutexAutoLock lock(m_con_mutex); //bulk comment-out
		our_peer_id = m_con.GetPeerID();
	}

	// Set peer id if not set already
	if(myplayer->peer_id == PEER_ID_INEXISTENT)
		myplayer->peer_id = our_peer_id;
	// Check that an existing peer_id is the same as the connection's
	if (myplayer->peer_id != our_peer_id)
		return;

	MSGPACK_PACKET_INIT(TOSERVER_PLAYERPOS, 5);
	PACK(TOSERVER_PLAYERPOS_POSITION, myplayer->getPosition());
	PACK(TOSERVER_PLAYERPOS_SPEED, myplayer->getSpeed());
	PACK(TOSERVER_PLAYERPOS_PITCH, myplayer->getPitch());
	PACK(TOSERVER_PLAYERPOS_YAW, myplayer->getYaw());
	PACK(TOSERVER_PLAYERPOS_KEY_PRESSED, myplayer->keyPressed);
	// Send as unreliable
	Send(0, buffer, false);
}
开发者ID:ChunHungLiu,项目名称:freeminer,代码行数:42,代码来源:fm_clientpacketsender.cpp


示例2: extend_heap

/* 
 * Requires:
 *   words: the number of words to increase the heap by
 *   next: next pointer at the end of the linked list, to be set to the 
 	   header of the new block
 * Effects:
 *   Extend the heap with a free block and return that block's address.
 */
static void *
extend_heap(size_t words) 
{
	size_t size;
	void *bp;

	/* 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);
	printf("Before extended block is added to the free list\n");
	checkheap(1);
	/* Initialize the new node pointers, next precedes previous */
	/* The previous point points to the header of the previous block*/	
	
	/*PUT(bp, NULL);
	PUT(bp + WSIZE, HDRP(next));*/

	/* 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 */
	
	/* If list start is NULL, initialize the start to the pointer to the
	 * added block
	 */
	if (list_start == NULL) {
		list_start = (struct node *)bp;
		list_start->next = list_start;
		list_start->previous = list_start;
	}

	printf("For isolation\n");

	add_to_front(bp);
	printf("After extended block is added to the free list\n");
	checkheap(1);
	printf("Entering coalesce from extend_heap\n");
	/* Coalesce if the previous block was free. */
	return (coalesce(bp));
}
开发者ID:gowtamvamsi,项目名称:COMP321-malloc,代码行数:50,代码来源:mm.c


示例3: free

/* 
 * free - Free a block 
 */
void free(void *bp)
{
    if (bp == 0) 
        return;

    size_t size = GET_SIZE(HDRP(bp));
    if (heap_listp == 0){
        mm_init();
    }

    PUT(HDRP(bp), PACK(size, 0));
    PUT(FTRP(bp), PACK(size, 0));
    insert_node(bp, size);
    coalesce(bp);
    line_count++;
    if (CHECK && CHECK_FREE) {
    mm_check('f', bp, size);
  }

}
开发者ID:PoojaManglaCMU,项目名称:MallocImplementation,代码行数:23,代码来源:mm_trace.c


示例4: mm_init

/**
 * Initialize the memory manager.
 * @param - void no parameter passed in
 * @return - int 0 for success or -1 for failure
 */
int mm_init(void) {
	
	/*return -1 if unable to get heap space*/
	if ((heap_listp = mem_sbrk(2*BLKSIZE)) == NULL) 
		return -1;

	PUT(heap_listp, 0); 								/* alignment padding */ 
	PUT(heap_listp + (1*WSIZE), PACK(BLKSIZE, 1)); 		/* prologue header */
	PUT(heap_listp + (2*WSIZE), 0); 					/* prev pointer */
	PUT(heap_listp + (3*WSIZE), 0); 					/* next pointer */
	PUT(heap_listp + BLKSIZE, PACK(BLKSIZE, 1)); 		/* prologue footer */ 
	PUT(heap_listp+  BLKSIZE + WSIZE, PACK(0, 1)); 		/* epilogue header */ 
	listp = heap_listp + DSIZE; 

	/* Extend the empty heap with a free block of BLKSIZE bytes */
	if (extend_heap(BLKSIZE) == NULL){ 
		return -1;
	}
	return 0;
}
开发者ID:highlanderkev,项目名称:Malloc_Lab,代码行数:25,代码来源:mm.c


示例5: free_ptr

/* put header, footer and free_list pointers in a free block */
void free_ptr(void *ptr, void *prev, void *next, unsigned size)
{
    unsigned header = PACK(size, 0);
    // header
    PUT_INT(HDRP(ptr), header);
    // footer
    PUT_INT(FTRP(ptr), header);
    // prev and next
    PUT(PREV_PTR(ptr), prev);
    PUT(NEXT_PTR(ptr), next);
}
开发者ID:RCSL-HKUST,项目名称:heterosim,代码行数:12,代码来源:mm.c


示例6: return

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;


    /* call for more memory space */
    if ((bp = mem_sbrk(size)) == (void *)-1)
        return (NULL);

    /* Initialize free block header/footer and the epilogue header */
    SET_HDRP(bp, PACK(size, 0));         /* free block header */
    SET_FTRP(bp, PACK(size, 0));         /* free block footer */
    SET_HDRP(NEXT_BLKP(bp), PACK(0, 1)); /* new epilogue header */

    /* coalesce bp with next and previous blocks */
    return coalesce(bp);
}
开发者ID:fast1234,项目名称:Dynamic-Memory-Allocator,代码行数:20,代码来源:mm.c


示例7: 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));

	/* Reset Header and Footer to be free */
	PUT(HDRP(bp), PACK(size, 0));
	PUT(FTRP(bp), PACK(size, 0));
	coalesce(bp);

	checkheap(1);
}
开发者ID:gowtamvamsi,项目名称:COMP321-malloc,代码行数:27,代码来源:mm.c


示例8: mm_free

void mm_free(void *currblock)
{
  size_t size = GETSIZE(HEADER(currblock)); // Size of block 
  
  UNSETRTAG(HEADER(NEXT(currblock)));
  
  PUT(HEADER(currblock), PACK(size, 0));
  PUT(FOOTER(currblock), PACK(size, 0));
  
  insertfree(currblock, size);
  
  coalesce(currblock);
  
  line_count++;
  if (MMCHECK) {
    mm_check('f', currblock, size);
  }

  return;
}
开发者ID:js6450,项目名称:CSO,代码行数:20,代码来源:mm.c


示例9: mm_init

/*
 * Initialize: return -1 on error, 0 on success.
 */
int mm_init(void) {
    /* Create the initial empty heap */
    if ((heap_listp = mem_sbrk(4*WSIZE)) == (void *)-1) //line:vm:mm:begininit
    return -1;
    PUT(heap_listp, 0);                          /* Alignment padding */
    PUT(heap_listp + (1*WSIZE), PACK(DSIZE, 1)); /* Prologue header */ 
    PUT(heap_listp + (2*WSIZE), PACK(DSIZE, 1)); /* Prologue footer */ 
    PUT(heap_listp + (3*WSIZE), PACK(0, 1));     /* Epilogue header */
    heap_listp += (2*WSIZE); 

    #ifdef NEXT_FIT
    rover = heap_listp;
#endif
/* $begin mminit */

    /* Extend the empty heap with a free block of CHUNKSIZE bytes */
    if (extend_heap(CHUNKSIZE/WSIZE) == NULL) 
        return -1;
    return 0;
}
开发者ID:kkamilla,项目名称:ComputerSystems-15213,代码行数:23,代码来源:mmcheckpoint.c


示例10: DSTACK

void Server::SendHP(u16 peer_id, u8 hp)
{
	DSTACK(FUNCTION_NAME);
	std::ostringstream os(std::ios_base::binary);

	MSGPACK_PACKET_INIT(TOCLIENT_HP, 1);
	PACK(TOCLIENT_HP_HP, hp);

	// Send as reliable
	m_clients.send(peer_id, 0, buffer, true);
}
开发者ID:carriercomm,项目名称:freeminer,代码行数:11,代码来源:fm_serverpacketsender.cpp


示例11: printf

static void *extend_heap(size_t words){
#ifdef DEBUG
    printf("call a extend[%d] for %dbyte\n",++exCnt,words*WSIZE);
#endif
    char *bp;
    size_t size;

    size = (words%2)?(words+1)*WSIZE : words*WSIZE;
    if((int)(bp = mem_sbrk(size)) == -1)
        return NULL;
#ifdef DEBUG
    printf("tot heapsize = %d\n",(char*)bp-heap_listp+size+DSIZE);
#endif
    PUT(HDRP(bp), PACK(size, 0));
    PUT(FTRP(bp), PACK(size, 0));
    PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1));/*next block does not exsist, but the header of it does, the epiloge*/
    /*Initialize */
    //printf("bp from exh %x\n",bp);
    return coalesce(bp);
}
开发者ID:cmxcn,项目名称:CSAPP_labs,代码行数:20,代码来源:mm_Impl_nf.c


示例12: mem_sbrk

static void *extend_heap(size_t words)
{
        char *bp;
        size_t size;

        /* Allocate an even number of words to maintain aligment */
        size = (words % 2) ? (words+1) * WSIZE : words * WSIZE;
        bp = mem_sbrk(size);
        if ((long)bp == -1)
                return NULL;

        /* Initialize free block header/footer and the epilogue header */
        int prev_alloc = GET_ALLOC_PREV(HDRP(bp));
        PUT(HDRP(bp), PACK(size, prev_alloc)); /* Free block header */
        PUT(FTRP(bp), PACK(size, prev_alloc)); /* Free block footer */
        PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1));  /* New epilogue header */

        /* Coalesce if the previous block was free */
        return coalesce(bp);
}
开发者ID:lirenjie95,项目名称:CSAPP,代码行数:20,代码来源:9-18.c


示例13: mm_init

int mm_init(void)
{
    /* create the initial empty heap */
    if( (heap_list_ptr = mem_sbrk(6 * WSIZE)) == (void *)-1 )
        return -1;
    PUT( heap_list_ptr + (2 * WSIZE), 0 ); // alignment padding
    PUT( heap_list_ptr + (3 * WSIZE), PACK(DSIZE, 1) ); // prologue HDRPer
    PUT( heap_list_ptr + (4 * WSIZE), PACK(DSIZE, 1) ); // prologue FTRPer
    PUT( heap_list_ptr + (5 * WSIZE), PACK(0, 3) ); // epilogue HDRPer
    heap_list_ptr += (4 * WSIZE);
    /*init the global variables*/
    NULL_POINTER = (void *)0x800000000; 
    root = NULL_POINTER;
    list_for_16 = NULL_POINTER;
    list_for_8 = NULL_POINTER;
    /* Extend the empty heap with a free block of CHUNKSIZE bytes */
    if( extend_heap(MIN_SIZE_IN_TREE)==NULL )
        return -1;
    return 0;
}
开发者ID:MinghanChen,项目名称:malloc_lab,代码行数:20,代码来源:mm.c


示例14: mm_init

/*
 * mm_init - initialize the malloc package.
 */
int mm_init(void)
{
    /* Create the initial empty heap */
    if((heap_listp = mem_sbrk(MIN_BLCK_SIZE)) == (void *) -1)
        return -1;
    PUT(heap_listp + (0*WSIZE), PACK(3*WSIZE, 1));  /* Prologue header */
    PUT(heap_listp + (1*WSIZE), 0);                 /* Prologue prev */
    PUT(heap_listp + (2*WSIZE), 0);                 /* Prologue next */
    PUT(heap_listp + (3*WSIZE), PACK(0, 1));        /* epilogue header */

    free_listp = heap_listp + (1*WSIZE);
    prologue = heap_listp + (1*WSIZE);
    epilogue = heap_listp + (3*WSIZE);
    mm_check();

    /* Extend the empty heap with a free block of CHUNKSIZE bytes */
    if (extend_heap(CHUNKSIZE/WSIZE) == NULL)
        return (-1);
    return 0;
}
开发者ID:johannbrynjar,项目名称:malloclab,代码行数:23,代码来源:mm.c


示例15: mm_init

//Initialize the heap in this block by making the prologue epilogue and providing extra padding.Also the prologue has space for prev/next and an empty padding since minimum block size is 24 which is max(min all block size, min free block size)
int mm_init(void)
{
    if((heap_listp = mem_sbrk(2 * OVERHEAD)) == NULL){                                     
        return -1;
    }

    PUT(heap_listp, 0);                                         
    PUT(heap_listp + WSIZE, PACK(OVERHEAD, 1));                 
    PUT(heap_listp + DSIZE, 0);                                 
    PUT(heap_listp + DSIZE + WSIZE, 0);                         
    PUT(heap_listp + OVERHEAD, PACK(OVERHEAD, 1));              
    PUT(heap_listp + WSIZE + OVERHEAD, PACK(0, 1));             
    head = heap_listp + DSIZE;                                  

    if(extend_heap(CHUNKSIZE / WSIZE) == NULL){                 
        return -1;
    }

    return 0;
}
开发者ID:bremerle3,项目名称:cse361,代码行数:21,代码来源:mm_70.c


示例16: mm_init

/*
 * initializes the dynamic allocator
 * arguments: none
 * returns: 0, if successful
 *          1, if an error occurs
 */
int mm_init(void) {
    if ((heap_listp = mem_sbrk(6 * WSIZE)) == (void *)-1)
    {
	return (-1);
    }
    PUT(heap_listp, 0);                            /* Alignment padding */
    PUT(heap_listp + (1 * WSIZE), PACK(2*DSIZE, 1)); /* Prologue header */
    PUT(heap_listp + (2 * WSIZE), 0);              /*next address is null*/
    PUT(heap_listp + (3 * WSIZE), 0);              /*prev address is null*/
    PUT(heap_listp + (4 * WSIZE), PACK(2*DSIZE, 1)); /* Prologue footer */
    PUT(heap_listp + (5 * WSIZE), PACK(0, 1));     /* Epilogue header */
    heap_listp += (2 * WSIZE);
    free_list = heap_listp;
    /* Extend the empty heap with a free block of CHUNKSIZE bytes. */
    if (extend_heap(CHUNKSIZE / WSIZE) == NULL)
    {
	return (-1);
    }
    return 0;
}
开发者ID:dukelv,项目名称:csci033,代码行数:26,代码来源:mm.c


示例17: realloc_by_merge

/*
** Realloc by merging the next if it isn't reserved.
** Return 0 if the realloc has been done, -1 otherwise
*/
static int	realloc_by_merge(t_ptr block, size_t size)
{
    size_t	total_size;
    size_t	real_size;

    if (size <= DWORD_SIZE)
        real_size = size + EXTRA_SIZE;
    else
    {
        real_size = ((size + EXTRA_SIZE + DWORD_SIZE - 1)
                     / DWORD_SIZE) * DWORD_SIZE;
    }
    total_size = GET_B_SIZE(block) + GET_B_SIZE(GET_NEXT(block));
    if (IS_B_ALLOC(GET_NEXT(block)) || total_size < real_size)
        return (-1);
    SET(GET_HEAD(block), PACK(total_size, 0));
    SET(GET_FOOT(block), PACK(total_size, 0));
    heap_reserve(block, real_size);
    return (0);
}
开发者ID:Raphy,项目名称:malloc,代码行数:24,代码来源:realloc.c


示例18: mm_init

/*
 * Initialize: return -1 on error, 0 on success.
 */
int mm_init(void) 
{

  if((heapStart = mem_sbrk(4 * WSIZE)) == (void *)-1) return -1 ;
  //allocation failed
  //heapStart contains first byte of heap, will not change
  PUT(heapStart, 0) ; //alignment padding
  PUT(heapStart + WSIZE , PACK(DSIZE, 1)) ; // prologue header
  PUT(heapStart + (2*WSIZE), PACK(DSIZE,1)) ; //prologue footer
  PUT(heapStart + (3*WSIZE), PACK(0,1)); //epilogue
  prologue = heapStart + WSIZE ;
  epilogue = heapStart + (3*WSIZE) ;
  firstFBP = NULL ; // set first free block to epilogue
  //will be free after extend_heap called
  
  extend_heap(CHUNKSIZE*2, EXT_INIT) ;
  dmm_checkheap(319);
  ASSERT(validFreeList(firstFBP)) ;
  return 0;
}
开发者ID:sam1323123,项目名称:Projects,代码行数:23,代码来源:mem_exp.c


示例19: PUT

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 ((long)(bp = mem_sbrk(size)) == -1)
        return NULL;
    //printf("size %d\n",(int)(size));
    /* 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 */

    //print_list();

    /* Coalesce if the previous block was free */
    return coalesce((void*)bp);
}
开发者ID:msr23trini,项目名称:malloclab,代码行数:20,代码来源:mm.c


示例20: extend_heap

static void *
extend_heap(size_t words) 
{
  char *bp;
  size_t size;

  /* Arithmetic 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 next and previous block is free*/
  return coalesce(bp);
}
开发者ID:nik-6947,项目名称:malloc,代码行数:20,代码来源:mm.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PACKET函数代码示例发布时间:2022-05-30
下一篇:
C++ PA函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap