Skip to main content

HeapResizableBuffer

Struct HeapResizableBuffer 

Source
pub struct HeapResizableBuffer { /* private fields */ }
Expand description

Heap-allocated resizable buffer.

Matches HeapResizableBuffer:

HeapResizableBuffer(size_t initialSize = 4096, size_t maxSizeStep = 1024 * 1024);
// initialSize = max(AlignSize(initialSize, true), s_MinBufferSize);
// m_maxSizeStep = max(AlignSize(maxSizeStep, false), s_MinBufferSize);

span<std::byte> BeginToGrow() {
    auto newSize = m_bufferSize + std::min(m_bufferSize, m_maxSizeStep);
    ...
}

Implementations§

Source§

impl HeapResizableBuffer

Source

pub fn new(initial_size: usize, max_size_step: usize) -> Self

Create a new buffer.

  • initial_size is aligned up and floored at MIN_BUFFER_SIZE.
  • max_size_step is aligned down and floored at MIN_BUFFER_SIZE.
Source

pub fn capacity(&self) -> usize

Current buffer capacity in bytes.

Source

pub fn max_size_step(&self) -> usize

Current max growth step in bytes.

Trait Implementations§

Source§

impl Debug for HeapResizableBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HeapResizableBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl ResizableBuffer for HeapResizableBuffer

Source§

fn get_buffer(&self) -> &[u8]

Get the current buffer as a byte slice.
Source§

fn get_buffer_mut(&mut self) -> &mut [u8]

Get the current buffer as a mutable byte slice.
Source§

fn begin_to_grow(&mut self) -> Result<&mut [u8], BufferError>

Begin a grow operation and return the new (larger) buffer. Existing content is copied to the FRONT of the new buffer. The caller may relocate content; then call commit() (or rollback() to cancel).
Source§

fn commit(&mut self)

Complete the active grow operation.
Source§

fn rollback(&mut self)

Cancel the active grow operation.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.