pub struct BufPoolAllocation { /* private fields */ }Expand description
A RAII safe allocation object containing allocated buffers
§Lifetime
The object can/may outlive the scope that created it, while also being able to transfer across
threads. As, internally the BufPool tracks all the active allocations and delays the drop
until every allocation and all there references are dropped from memory.
§Example
use frozen_core::{
bufpool::{BufPool, BufPoolCfg, BufferPointer},
utils::BufferSize,
};
const BUF_SIZE: BufferSize = BufferSize::S16;
let pool = BufPool::new(BufPoolCfg {
buffer_size: BUF_SIZE,
max_memory: BUF_SIZE as usize * 0x10,
});
let alloc = pool.allocate(0x0A);
assert_eq!(alloc.length(), 0x0A);
assert!(!alloc.first().is_null());
assert_eq!(alloc.allocated_bytes(), BUF_SIZE as usize * 0x0A);
let ptrs: Vec<BufferPointer> = alloc.iter().collect();
assert_eq!(ptrs.len(), 0x0A);Implementations§
Source§impl BufPoolAllocation
impl BufPoolAllocation
Sourcepub const fn first(&self) -> BufferPointer
pub const fn first(&self) -> BufferPointer
Returns a BufferPointer to the first buffer from the allocated list of buffers
NOTE: The returned BufferPointer can also be used as a base_pointer to operate on
the entire allocated memory slice.
§Example
use frozen_core::{
bufpool::{BufPool, BufPoolCfg},
utils::BufferSize,
};
const BUF_SIZE: BufferSize = BufferSize::S32;
let pool = BufPool::new(BufPoolCfg {
buffer_size: BUF_SIZE,
max_memory: BUF_SIZE as usize * 0x0A,
});
let alloc = pool.allocate(0x0A);
assert!(!alloc.first().is_null());Sourcepub const fn length(&self) -> usize
pub const fn length(&self) -> usize
Returns the total number of allocated buffers
IMPORTANT: The returned value is always equal to the required value using while
calling BufPool::allocate.
§Example
use frozen_core::{
bufpool::{BufPool, BufPoolCfg},
utils::BufferSize,
};
const BUF_SIZE: BufferSize = BufferSize::S64;
let pool = BufPool::new(BufPoolCfg {
buffer_size: BUF_SIZE,
max_memory: BUF_SIZE as usize * 0x0A,
});
let alloc = pool.allocate(0x0A);
assert_eq!(alloc.length(), 0x0A);Sourcepub const fn allocated_bytes(&self) -> usize
pub const fn allocated_bytes(&self) -> usize
Returns the total number of bytes of memory allocated
§Example
use frozen_core::{
bufpool::{BufPool, BufPoolCfg},
utils::BufferSize,
};
const BUF_SIZE: BufferSize = BufferSize::S16;
let pool = BufPool::new(BufPoolCfg {
buffer_size: BUF_SIZE,
max_memory: BUF_SIZE as usize * 0x0A,
});
let alloc = pool.allocate(0x0A);
assert_eq!(alloc.allocated_bytes(), BUF_SIZE as usize * 0x0A);Sourcepub fn iter(&self) -> BufPoolAllocationIter ⓘ
pub fn iter(&self) -> BufPoolAllocationIter ⓘ
A custom Iterator implementation to enable iteration over the list of allocated buffers
from BufPoolAllocation
NOTE: Each yielded pointer refers to a unique individual buffer each of size
BufPoolCfg::buffer_size.
§Example
use frozen_core::{
bufpool::{BufPool, BufPoolCfg, BufferPointer},
utils::BufferSize,
};
const BUF_SIZE: BufferSize = BufferSize::S16;
let pool = BufPool::new(BufPoolCfg {
buffer_size: BUF_SIZE,
max_memory: BUF_SIZE as usize * 0x14,
});
let alloc = pool.allocate(0x0A);
let ptrs: Vec<BufferPointer> = alloc.iter().collect();
assert_eq!(ptrs.len(), 0x0A);