You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
feat(PP,ByteStream): new counting memory allocator
This commit is contained in:
@ -37,6 +37,7 @@
|
||||
#include "serializeable.h"
|
||||
#include "any.hpp"
|
||||
#include "nullstring.h"
|
||||
#include "countingallocator.h"
|
||||
|
||||
class ByteStreamTestSuite;
|
||||
|
||||
@ -46,7 +47,7 @@ namespace messageqcpp
|
||||
{
|
||||
typedef boost::shared_ptr<ByteStream> SBS;
|
||||
using BSSizeType = uint64_t;
|
||||
|
||||
using BSBufType = uint8_t;
|
||||
/**
|
||||
* @brief A class to marshall bytes as a stream
|
||||
*
|
||||
@ -78,6 +79,7 @@ class ByteStream : public Serializeable
|
||||
* default ctor
|
||||
*/
|
||||
EXPORT explicit ByteStream(BSSizeType initSize = 8192); // multiples of pagesize are best
|
||||
explicit ByteStream(allocators::CountingAllocator<BSBufType>* alloc, uint32_t initSize = 8192);
|
||||
/**
|
||||
* ctor with a uint8_t array and len initializer
|
||||
*/
|
||||
@ -466,6 +468,9 @@ class ByteStream : public Serializeable
|
||||
void doCopy(const ByteStream& rhs);
|
||||
|
||||
private:
|
||||
BSBufType* allocate(const size_t size);
|
||||
void deallocate(BSBufType* ptr);
|
||||
|
||||
// Put struct `MemChunk` declaration here, to avoid circular dependency.
|
||||
struct MemChunk
|
||||
{
|
||||
@ -474,11 +479,13 @@ class ByteStream : public Serializeable
|
||||
uint8_t data[];
|
||||
};
|
||||
|
||||
uint8_t* fBuf; /// the start of the allocated buffer
|
||||
uint8_t* fCurInPtr; // the point in fBuf where data is inserted next
|
||||
uint8_t* fCurOutPtr; // the point in fBuf where data is extracted from next
|
||||
BSSizeType fMaxLen; // how big fBuf is currently
|
||||
std::vector<std::shared_ptr<uint8_t[]>> longStrings; // Stores `long strings`.
|
||||
BSBufType* fBuf; /// the start of the allocated buffer
|
||||
BSBufType* fCurInPtr; // the point in fBuf where data is inserted next
|
||||
BSBufType* fCurOutPtr; // the point in fBuf where data is extracted from next
|
||||
BSSizeType fMaxLen; // how big fBuf is currently
|
||||
// Stores `long strings`.
|
||||
std::vector<std::shared_ptr<uint8_t[]>> longStrings;
|
||||
allocators::CountingAllocator<BSBufType>* allocator = nullptr;
|
||||
};
|
||||
|
||||
template <int W, typename T = void>
|
||||
@ -533,7 +540,7 @@ inline ByteStream::ByteStream(const uint8_t* bp, BSSizeType len) : fBuf(nullptr)
|
||||
}
|
||||
inline ByteStream::~ByteStream()
|
||||
{
|
||||
delete[] fBuf;
|
||||
deallocate(fBuf);
|
||||
}
|
||||
|
||||
inline const uint8_t* ByteStream::buf() const
|
||||
@ -558,7 +565,7 @@ inline BSSizeType ByteStream::lengthWithHdrOverhead() const
|
||||
}
|
||||
inline void ByteStream::reset()
|
||||
{
|
||||
delete[] fBuf;
|
||||
deallocate(fBuf);
|
||||
fMaxLen = 0;
|
||||
fCurInPtr = fCurOutPtr = fBuf = nullptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user