INNER CODE UNIT · Rust
new
rustformers/llm · crates/ggml/src/lib.rs:296
pub fn new(size: usize) -> Self {
let layout = Layout::from_size_align(size, BUFFER_ALIGN).unwrap();
unsafe {
Buffer {
data: std::alloc::alloc(layout).cast(),
layout,
}
}
}
/// Returns the size of the buffer in bytes
pub fn size(&self) -> usize {
self.layout.size()
}
}
impl Drop for Buffer {