use std::alloc::Layout;
pub struct RegisteredBuffers {
pub allocations: Vec<(*mut u8, Layout)>,
}
unsafe impl Send for RegisteredBuffers {}
impl std::fmt::Debug for RegisteredBuffers {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"RegisteredBuffers(count={}, size={})",
self.allocations.len(),
self.allocations
.first()
.map_or(0, |(_, layout)| layout.size())
)
}
}
impl Drop for RegisteredBuffers {
fn drop(&mut self) {
for (ptr, layout) in self.allocations.drain(..) {
unsafe {
std::alloc::dealloc(ptr, layout);
}
}
}
}