feat: Aether OS v2.6 Solarized Warm Edition, x86_64 Rust microkernel, bootable ISO, and CA assessment reports
258148b verified Download CA6_Rust_Micro_OS_Project/src/memory.rs from varad130407/oslab: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/datasets/varad130407/oslab/resolve/main/CA6_Rust_Micro_OS_Project/src/memory.rs
- Command line
-
hf download hf://datasets/varad130407/oslab/CA6_Rust_Micro_OS_Project/src/memory.rs
-
curl -L -o memory.rs https://huggingface.co/datasets/varad130407/oslab/resolve/main/CA6_Rust_Micro_OS_Project/src/memory.rs
1.02 kB
| pub struct Allocation { | |
| pub offset: usize, | |
| pub size: usize, | |
| } | |
| pub struct BumpAllocator { | |
| heap: Vec<u8>, | |
| next: usize, | |
| } | |
| impl BumpAllocator { | |
| pub fn new(capacity: usize) -> Self { | |
| assert!(capacity > 0, "allocator capacity must be positive"); | |
| Self { | |
| heap: vec![0; capacity], | |
| next: 0, | |
| } | |
| } | |
| pub fn allocate(&mut self, size: usize, alignment: usize) -> Option<Allocation> { | |
| if size == 0 || !alignment.is_power_of_two() { | |
| return None; | |
| } | |
| let aligned = (self.next + alignment - 1) & !(alignment - 1); | |
| let end = aligned.checked_add(size)?; | |
| if end > self.heap.len() { | |
| return None; | |
| } | |
| self.next = end; | |
| Some(Allocation { | |
| offset: aligned, | |
| size, | |
| }) | |
| } | |
| pub fn used(&self) -> usize { | |
| self.next | |
| } | |
| pub fn capacity(&self) -> usize { | |
| self.heap.len() | |
| } | |
| } | |