1 #include "pup_cmialloc.h"
3 void PUP_cmiAllocSizer::bytes(void *,size_t n,size_t itemSize,PUP::dataType) {
4 nBytes += n * itemSize;
7 void PUP_toCmiAllocMem::bytes(void *p, size_t n, size_t itemSize,
11 memcpy((void *)buf, p, n);
15 void PUP_fromCmiAllocMem::bytes(void *p, size_t n, size_t itemSize,
19 memcpy(p,(const void *)buf,n);
24 void PUP_cmiAllocSizer::pupCmiAllocBuf(void **msg) {
25 CmiChunkHeader chnk_hdr = *(BLKSTART(*msg));
26 pupCmiAllocBuf(msg, chnk_hdr.size);
29 void PUP_cmiAllocSizer::pupCmiAllocBuf(void **msg, size_t msg_size) {
31 //The cmialloced buf can only start at an aligned memory location
32 //So nbytes has to be aligned
33 nBytes = ALIGN8(nBytes);
35 nBytes += sizeof(CmiChunkHeader);
36 //Here the user buffer pointer will start, hence everything has to
37 //be aligned till here
38 nBytes += msg_size; //The actual size of the user message
42 void PUP_toCmiAllocMem::pupCmiAllocBuf(void **msg) {
43 pupCmiAllocBuf(msg, SIZEFIELD(msg));
46 void PUP_toCmiAllocMem::pupCmiAllocBuf(void **msg, size_t msg_size) {
48 CmiChunkHeader chnk_hdr;
50 buf = origBuf + ALIGN8_LONG(size());
52 chnk_hdr.size = msg_size;
53 chnk_hdr.setRef(origBuf - (buf + sizeof(CmiChunkHeader)));
55 //Copy the Chunk header
56 memcpy(buf, &chnk_hdr, sizeof(CmiChunkHeader));
57 buf += sizeof(CmiChunkHeader);
59 //Now buf is a memory aligned pointer
61 //While unpacking, this aligned pointer will be returned
62 memcpy(buf, *msg, msg_size);
66 void PUP_fromCmiAllocMem::pupCmiAllocBuf(void **msg) {
68 buf = (PUP::myByte *)(intptr_t)ALIGN8_LONG((intptr_t)buf);
70 //Now get the chunk header
71 CmiChunkHeader chnk_hdr;
72 //Get the Chunk header
73 memcpy(&chnk_hdr, buf, sizeof(CmiChunkHeader));
74 buf += sizeof(CmiChunkHeader);
76 //Now we are at the begining of the user buffer
79 //Move the local buf forward by size bytes
82 //update the reference count of the original buf
88 /***** END CmiAlloc'ed buffer management functions ***********/