Make it possible to define data alignment

This commit is contained in:
bjorn3
2019-03-30 16:45:58 +01:00
committed by Benjamin Bouvier
parent 443e48aee1
commit cb6268118c
5 changed files with 33 additions and 14 deletions

View File

@@ -97,7 +97,12 @@ impl Memory {
}
/// TODO: Use a proper error type.
pub fn allocate(&mut self, size: usize) -> Result<*mut u8, String> {
pub fn allocate(&mut self, size: usize, align: u8) -> Result<*mut u8, String> {
if self.position % align as usize != 0 {
self.position += align as usize - self.position % align as usize;
debug_assert!(self.position % align as usize == 0);
}
if size <= self.current.len - self.position {
// TODO: Ensure overflow is not possible.
let ptr = unsafe { self.current.ptr.add(self.position) };