本文整理汇总了C++中PACK函数的典型用法代码示例。如果您正苦于以下问题:C++ PACK函数的具体用法?C++ PACK怎么用?C++ PACK使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PACK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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));
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}