本文整理汇总了C++中MemoryBuffer::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::reserve方法的具体用法?C++ MemoryBuffer::reserve怎么用?C++ MemoryBuffer::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::reserve方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ThorExpand
size32_t ThorExpand(const void * src, size32_t srcSz, MemoryBuffer & dest)
{
size32_t sz;
memcpy(&sz, src, sizeof(size32_t));
size32_t bufSz = (sz == 0) ? (srcSz-sizeof(size32_t)) : sz;
void * buf = dest.reserve(bufSz);
return ThorExpand(src, srcSz, buf, bufSz);
}
示例2: ThorCompress
size32_t ThorCompress(const void * src, size32_t srcSz, MemoryBuffer & dest, size32_t threshold)
{
size32_t prev = dest.length();
size32_t dSz = srcSz + sizeof(size32_t);
void * d = dest.reserve(dSz);
size32_t ret = ThorCompress(src, srcSz, d, dSz, threshold);
dest.setLength(prev+ret);
return ret;
}
示例3: _receive
void CThorTransferGroup::_receive(ISocket * rcv)
{
CThorRowArray *received = new CThorRowArray();
rcv->set_block_mode(BF_SYNC_TRANSFER_PULL,0,TRANSFER_TIMEOUT);
size32_t bufferSz = rcv->receive_block_size();
if (bufferSz) {
MemoryBuffer mb;
void * receiveBlock = mb.reserve(bufferSz);
rcv->receive_block(receiveBlock,bufferSz);
received->deserialize(*allocator,deserializer,bufferSz,receiveBlock,false);
}
rcv->close();
rcv->Release();
receive(received); // frees receiveArray
}
示例4: LZMACompressToBuffer
void LZMACompressToBuffer(MemoryBuffer & out, size32_t len, const void * src)
{
CLZMA lzma;
size32_t outbase = out.length();
size32_t *sz = (size32_t *)out.reserve(len+sizeof(size32_t)*2);
*sz = len;
sz++;
*sz = lzma.compress(src,len,sz+1);
if (*sz>len) {
*sz = len;
memcpy(sz+1,src,len);
}
else
out.setLength(outbase+sizeof(size32_t)*2+*sz);
}
示例5: LZMADecompressToBuffer
void LZMADecompressToBuffer(MemoryBuffer & out, MemoryBuffer & in)
{
size32_t expsz;
size32_t cmpsz;
in.read(expsz).read(cmpsz);
void *o = out.reserve(expsz);
if (cmpsz!=expsz) {
CLZMA lzma;
size32_t written = lzma.expand(in.readDirect(cmpsz),cmpsz,o,expsz);
if (written!=expsz)
throw MakeStringException(0, "fastLZDecompressToBuffer - corrupt data(3) %d %d",written,expsz);
}
else
memcpy(o,in.readDirect(cmpsz),expsz);
}
示例6: unpack
void CJHTreeNode::unpack(const void *node, bool needCopy)
{
memcpy(&hdr, node, sizeof(hdr));
SwapBigEndian(hdr);
__int64 maxsib = keyHdr->getHdrStruct()->phyrec;
if (!hdr.isValid(keyHdr->getNodeSize()))
{
PROGLOG("hdr.leafFlag=%d",(int)hdr.leafFlag);
PROGLOG("hdr.rightSib=%" I64F "d",hdr.rightSib);
PROGLOG("hdr.leftSib=%" I64F "d",hdr.leftSib);
PROGLOG("maxsib=%" I64F "d",maxsib);
PROGLOG("nodeSize=%d", keyHdr->getNodeSize());
PROGLOG("keyBytes=%d",(int)hdr.keyBytes);
PrintStackReport();
throw MakeStringException(0, "Htree: Corrupt key node detected");
}
if (!hdr.leafFlag)
keyLen = keyHdr->getNodeKeyLength();
keyRecLen = keyLen + sizeof(offset_t);
char *keys = ((char *) node) + sizeof(hdr);
if (hdr.crc32)
{
unsigned crc = crc32(keys, hdr.keyBytes, 0);
if (hdr.crc32 != crc)
throw MakeStringException(0, "CRC error on key node");
}
if (hdr.leafFlag==1)
{
firstSequence = *(unsigned __int64 *) keys;
keys += sizeof(unsigned __int64);
_WINREV(firstSequence);
}
if(isMetadata())
{
unsigned short len = *reinterpret_cast<unsigned short *>(keys);
_WINREV(len);
expandedSize = len;
keyBuf = (char *) allocMem(len);
memcpy(keyBuf, keys+sizeof(unsigned short), len);
}
else if (isLeaf() && (keyType & HTREE_COMPRESSED_KEY))
{
{
MTIME_SECTION(queryActiveTimer(), "Compressed node expand");
expandedSize = keyHdr->getNodeSize();
bool quick = (keyType&HTREE_QUICK_COMPRESSED_KEY)==HTREE_QUICK_COMPRESSED_KEY;
#ifndef _OLD_VERSION
keyBuf = NULL;
if (quick)
rowexp.setown(expandQuickKeys(keys, needCopy));
if (!quick||!rowexp.get())
#endif
{
keyBuf = expandKeys(keys,keyLen,expandedSize,quick);
}
}
assertex(keyBuf||rowexp.get());
}
else
{
int i;
if (keyType & COL_PREFIX)
{
MTIME_SECTION(queryActiveTimer(), "COL_PREFIX expand");
if (hdr.numKeys) {
bool handleVariable = isVariable && isLeaf();
KEYRECSIZE_T workRecLen;
MemoryBuffer keyBufMb;
const char *source = keys;
char *target;
// do first row
if (handleVariable) {
memcpy(&workRecLen, source, sizeof(workRecLen));
_WINREV(workRecLen);
size32_t tmpSz = sizeof(workRecLen) + sizeof(offset_t);
target = (char *)keyBufMb.reserve(tmpSz+workRecLen);
memcpy(target, source, tmpSz);
source += tmpSz;
target += tmpSz;
}
else {
target = (char *)keyBufMb.reserveTruncate(hdr.numKeys * keyRecLen);
workRecLen = keyRecLen - sizeof(offset_t);
memcpy(target, source, sizeof(offset_t));
source += sizeof(offset_t);
target += sizeof(offset_t);
}
// this is where next row gets data from
const char *prev, *next = NULL;
unsigned prevOffset = 0;
if (handleVariable)
prevOffset = target-((char *)keyBufMb.bufferBase());
else
next = target;
unsigned char pack1 = *source++;
#ifdef _DEBUG
assertex(0==pack1); // 1st time will be always be 0
//.........这里部分代码省略.........