pub struct Ring<T> { /* private fields */ }
Expand description
A dynamic external memory allocator providing the functionality of a circular buffer.
See the module-level documentation for more.
Type parameters
T
is an integer type used to represent region sizes. You usually useu32
oru64
for this.
Implementations
sourceimpl<T: BinaryUInteger> Ring<T>
impl<T: BinaryUInteger> Ring<T>
sourcepub fn new(size: T) -> Self
pub fn new(size: T) -> Self
Construct a RingRegion
.
size
must be smaller than T::max_value() >> 1
(this is a precaution
taken not to cause unintentional overflows).
sourcepub fn alloc_back(&mut self, size: T) -> Option<(RingRegion<T>, T)>
pub fn alloc_back(&mut self, size: T) -> Option<(RingRegion<T>, T)>
Allocate a region of the size size
to the back of the allocated
region.
Returns a handle of the allocated region and its offset if the
allocation succeeds. Returns None
otherwise.
size
must not be zero.
sourcepub fn alloc_front(&mut self, size: T) -> Option<(RingRegion<T>, T)>
pub fn alloc_front(&mut self, size: T) -> Option<(RingRegion<T>, T)>
Allocate a region of the size size
to the front of the allocated
region.
Returns a handle of the allocated region and its offset if the
allocation succeeds. Returns None
otherwise.
size
must not be zero.
sourcepub fn alloc_back_aligned(
&mut self,
size: T,
align: T
) -> Option<(RingRegion<T>, T)>
pub fn alloc_back_aligned(
&mut self,
size: T,
align: T
) -> Option<(RingRegion<T>, T)>
Allocate a region of the size size
with a given alignment requirement
to the back of the allocated region.
Returns a handle of the allocated region and its offset if the
allocation succeeds. Returns None
otherwise.
align
must be a power of two.size
must not be zero.
sourcepub fn alloc_front_aligned(
&mut self,
size: T,
align: T
) -> Option<(RingRegion<T>, T)>
pub fn alloc_front_aligned(
&mut self,
size: T,
align: T
) -> Option<(RingRegion<T>, T)>
Allocate a region of the size size
with a given alignment requirement
to the front of the allocated region.
Returns a handle of the allocated region and its offset if the
allocation succeeds. Returns None
otherwise.
align
must be a power of two.size
must not be zero.
sourcepub fn dealloc_front(&mut self, r: RingRegion<T>)
pub fn dealloc_front(&mut self, r: RingRegion<T>)
Deallocate the frontmost (first) region.
r
must be the current frontmost region of Ring
.
Otherwise, Ring
might enter an inconsistent state and/or panic, but
does not cause an undefined behavior.
sourcepub fn dealloc_back(&mut self, r: RingRegion<T>)
pub fn dealloc_back(&mut self, r: RingRegion<T>)
Deallocate the backmost (last) region.
r
must be the current backmost region of Ring
.
Otherwise, Ring
might enter an inconsistent state and/or panic, but
does not cause an undefined behavior.