pub struct RwBuffers { /* private fields */ }
Expand description
An instance which controls the allocation of the new buffers or reusage of already created and free instances. This instance is not thread safe. The external mutex should be used.
Implementations§
Source§impl RwBuffers
impl RwBuffers
Sourcepub fn new(
buf_len: usize,
pre_init_cnt: usize,
bufs_cnt_lim: usize,
) -> RwBufferRes<Self>
pub fn new( buf_len: usize, pre_init_cnt: usize, bufs_cnt_lim: usize, ) -> RwBufferRes<Self>
Creates new instance wshich holds the base reference in the inner storage with the capacity bounds.
§Arguments
-
buf_len
- a usize length of each buffer instance in bytes where the payload is located. -
pre_init_cnt
- a usize an initial pre allocated slots with created instances. -
bufs_cnt_lim
- a maximum amount of the available slots. Determines the capacity bounds.
§Returns
A Result in form of RwBufferRes is returned with:
-
Result::Ok with the RwBuffers instance
-
Result::Err with error type is returned:
- RwBufferError::InvalidArguments is returned when the arguments are incorrect.
Sourcepub fn new_unbounded(buf_len: usize, pre_init_cnt: usize) -> Self
pub fn new_unbounded(buf_len: usize, pre_init_cnt: usize) -> Self
Sourcepub fn allocate(&mut self) -> RwBufferRes<RwBuffer>
pub fn allocate(&mut self) -> RwBufferRes<RwBuffer>
Allocates either a new buffer or reuse the free. If the instance is created with bounds then in case if no free slots available returns error.
§Returns
A Result in form of RwBufferRes is returned with:
-
Result::Ok with the RwBuffers instance
-
Result::Err with RwBufferError::OutOfBuffers error.
Sourcepub fn allocate_in_place(&mut self) -> RwBuffer
pub fn allocate_in_place(&mut self) -> RwBuffer
Sourcepub fn compact(&mut self, cnt: usize) -> usize
pub fn compact(&mut self, cnt: usize) -> usize
Retains the buffer list by removing any unused buffers as many times
as set in the argument cnt
. It does not guaranty than the selected
amount will be freed.
§Arguments
cnt
- how many slots to clean before exit.
§Returns
A usize is returned which indicates how many instances was removed
before the cnt
was reached.