Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::MemoryStream Class Reference
Inheritance diagram for duckdb::MemoryStream:
Collaboration diagram for duckdb::MemoryStream:

Public Member Functions

 MemoryStream (Allocator &allocator, idx_t capacity=DEFAULT_INITIAL_CAPACITY)
 Create a new owning MemoryStream with an internal backing buffer with the specified capacity. The stream will own the backing buffer, resize it when needed and free its memory when the stream is destroyed.
 MemoryStream (idx_t capacity=DEFAULT_INITIAL_CAPACITY)
 Create a new owning MemoryStream with an internal backing buffer with the specified capacity. The stream will own the backing buffer, resize it when needed and free its memory when the stream is destroyed.
 MemoryStream (data_ptr_t buffer, idx_t capacity)
 Create a new non-owning MemoryStream over the specified external buffer and capacity. The stream will not take ownership of the backing buffer, will not attempt to resize it and will not free the memory when the stream is destroyed.
 MemoryStream (const MemoryStream &)=delete
 Cant copy!
MemoryStream & operator= (const MemoryStream &)=delete
 MemoryStream (MemoryStream &&other) noexcept
MemoryStream & operator= (MemoryStream &&other) noexcept
void WriteData (const_data_ptr_t buffer, idx_t write_size) override
 Write data to the stream. Throws if the write would exceed the capacity of the stream and the backing buffer is not owned by the stream.
void GrowCapacity (idx_t write_size)
void ReadData (data_ptr_t buffer, idx_t read_size) override
 Read data from the stream. Throws if the read would exceed the capacity of the stream.
void ReadData (QueryContext context, data_ptr_t buffer, idx_t read_size) override
void Rewind ()
 Rewind the stream to the start, keeping the capacity and the backing buffer intact.
void Release ()
 Release ownership of the backing buffer and turn a owning stream into a non-owning one. The stream will no longer be responsible for freeing the data. The stream will also no longer attempt to automatically resize the buffer when the capacity is reached.
data_ptr_t GetData () const
 Get a pointer to the underlying backing buffer.
idx_t GetPosition () const
 Get the current position in the stream.
idx_t GetCapacity () const
 Get the capacity of the stream.
void SetPosition (idx_t position)
 Set the position in the stream.
Public Member Functions inherited from duckdb::WriteStream
template<class T>
void Write (T element)
Public Member Functions inherited from duckdb::ReadStream
template<class T>
T Read ()
template<class T>
T Read (QueryContext context)

Static Public Attributes

static constexpr idx_t DEFAULT_INITIAL_CAPACITY = 512

Private Attributes

optional_ptr< Allocator > allocator
idx_t position
idx_t capacity
data_ptr_t data

Constructor & Destructor Documentation

◆ MemoryStream() [1/4]

duckdb::MemoryStream::MemoryStream ( Allocator & allocator,
idx_t capacity = DEFAULT_INITIAL_CAPACITY )
explicit

Create a new owning MemoryStream with an internal backing buffer with the specified capacity. The stream will own the backing buffer, resize it when needed and free its memory when the stream is destroyed.

100965 : allocator(&allocator_p), position(0), capacity(capacity) {
100966 D_ASSERT(capacity != 0 && IsPowerOfTwo(capacity));
100967 data = allocator_p.AllocateData(capacity);
100968}
Here is the caller graph for this function:

◆ MemoryStream() [2/4]

duckdb::MemoryStream::MemoryStream ( idx_t capacity = DEFAULT_INITIAL_CAPACITY)
explicit

Create a new owning MemoryStream with an internal backing buffer with the specified capacity. The stream will own the backing buffer, resize it when needed and free its memory when the stream is destroyed.

100970 : MemoryStream(Allocator::DefaultAllocator(), capacity) {
100971}
MemoryStream(Allocator &allocator, idx_t capacity=DEFAULT_INITIAL_CAPACITY)
Create a new owning MemoryStream with an internal backing buffer with the specified capacity....
Definition duckdb.cpp:100964
Here is the call graph for this function:

◆ MemoryStream() [3/4]

duckdb::MemoryStream::MemoryStream ( data_ptr_t buffer,
idx_t capacity )
explicit

Create a new non-owning MemoryStream over the specified external buffer and capacity. The stream will not take ownership of the backing buffer, will not attempt to resize it and will not free the memory when the stream is destroyed.

100973 : position(0), capacity(capacity), data(buffer) {
100974}

◆ MemoryStream() [4/4]

duckdb::MemoryStream::MemoryStream ( MemoryStream && other)
noexcept
100982 {
100983 // Move the data from the other stream into this stream
100984 data = other.data;
100985 position = other.position;
100986 capacity = other.capacity;
100987 allocator = other.allocator;
100988
100989 // Reset the other stream
100990 other.data = nullptr;
100991 other.position = 0;
100992 other.capacity = 0;
100993 other.allocator = nullptr;
100994}

◆ ~MemoryStream()

duckdb::MemoryStream::~MemoryStream ( )
override
100976 {
100977 if (allocator && data) {
100978 allocator->FreeData(data, capacity);
100979 }
100980}

Member Function Documentation

◆ operator=()

MemoryStream & duckdb::MemoryStream::operator= ( MemoryStream && other)
noexcept
100996 {
100997 if (this != &other) {
100998 // Free the current data
100999 if (allocator) {
101000 allocator->FreeData(data, capacity);
101001 }
101002
101003 // Move the data from the other stream into this stream
101004 data = other.data;
101005 position = other.position;
101006 capacity = other.capacity;
101007 allocator = other.allocator;
101008
101009 // Reset the other stream
101010 other.data = nullptr;
101011 other.position = 0;
101012 other.capacity = 0;
101013 other.allocator = nullptr;
101014 }
101015 return *this;
101016}

◆ WriteData()

void duckdb::MemoryStream::WriteData ( const_data_ptr_t buffer,
idx_t write_size )
overridevirtual

Write data to the stream. Throws if the write would exceed the capacity of the stream and the backing buffer is not owned by the stream.

Implements duckdb::WriteStream.

101018 {
101019 GrowCapacity(write_size);
101020 memcpy(data + position, source, write_size);
101021 position += write_size;
101022}

◆ GrowCapacity()

void duckdb::MemoryStream::GrowCapacity ( idx_t write_size)
101024 {
101025 const auto old_capacity = capacity;
101026 while (position + write_size > capacity) {
101027 if (allocator) {
101028 capacity *= 2;
101029 } else {
101030 throw SerializationException("Failed to serialize: not enough space in buffer to fulfill write request");
101031 }
101032 }
101033 if (capacity != old_capacity) {
101034 data = allocator->ReallocateData(data, old_capacity, capacity);
101035 }
101036}

◆ ReadData() [1/2]

void duckdb::MemoryStream::ReadData ( data_ptr_t buffer,
idx_t read_size )
overridevirtual

Read data from the stream. Throws if the read would exceed the capacity of the stream.

Implements duckdb::ReadStream.

101038 {
101039 ReadData(QueryContext(), destination, read_size);
101040}
void ReadData(data_ptr_t buffer, idx_t read_size) override
Read data from the stream. Throws if the read would exceed the capacity of the stream.
Definition duckdb.cpp:101038
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadData() [2/2]

void duckdb::MemoryStream::ReadData ( QueryContext context,
data_ptr_t buffer,
idx_t read_size )
overridevirtual

Implements duckdb::ReadStream.

101042 {
101043 if (position + read_size > capacity) {
101044 throw SerializationException("Failed to deserialize: not enough data in buffer to fulfill read request");
101045 }
101046 memcpy(destination, data + position, read_size);
101047 position += read_size;
101048}

◆ Rewind()

void duckdb::MemoryStream::Rewind ( )

Rewind the stream to the start, keeping the capacity and the backing buffer intact.

101050 {
101051 position = 0;
101052}
Here is the caller graph for this function:

◆ Release()

void duckdb::MemoryStream::Release ( )

Release ownership of the backing buffer and turn a owning stream into a non-owning one. The stream will no longer be responsible for freeing the data. The stream will also no longer attempt to automatically resize the buffer when the capacity is reached.

101054 {
101055 allocator = nullptr;
101056}

◆ GetData()

data_ptr_t duckdb::MemoryStream::GetData ( ) const

Get a pointer to the underlying backing buffer.

101058 {
101059 return data;
101060}
Here is the caller graph for this function:

◆ GetPosition()

idx_t duckdb::MemoryStream::GetPosition ( ) const

Get the current position in the stream.

101062 {
101063 return position;
101064}
Here is the caller graph for this function:

◆ GetCapacity()

idx_t duckdb::MemoryStream::GetCapacity ( ) const

Get the capacity of the stream.

101066 {
101067 return capacity;
101068}

◆ SetPosition()

void duckdb::MemoryStream::SetPosition ( idx_t position)

Set the position in the stream.

101070 {
101071 position = position_p;
101072}
Here is the caller graph for this function:

The documentation for this class was generated from the following files: