1#[derive(Debug)]
3pub struct AlignedBuffer {
4 buf: Vec<usize>,
5 bytes: usize,
6}
7
8impl AlignedBuffer {
9 #[must_use]
11 pub fn with_capacity_bytes(bytes: usize) -> Self {
12 let word = std::mem::size_of::<usize>();
13 let len = bytes.div_ceil(word);
14 let buf = vec![0usize; len];
15 let bytes = len * word;
16 Self { buf, bytes }
17 }
18
19 #[must_use]
21 pub fn capacity_bytes(&self) -> usize {
22 self.bytes
23 }
24
25 pub fn as_mut_ptr<T>(&mut self) -> *mut T {
27 self.buf.as_mut_ptr().cast()
28 }
29}