pub struct Memory {
pub stack_memory_size: usize,
pub stack_offset: usize,
pub stack_start: usize,
pub heap_start: usize,
pub heap_alloc_offset: usize,
pub constant_memory_size: usize,
pub execution_mode: ExecutionMode,
pub debug: MemoryDebug,
/* private fields */
}Expand description
VM Memory Layout (from lower to higher addresses):
- Constant Memory: Pre-compiled constant data (read-only)
- Constant Heap Allocations: Strings and other heap data allocated during constant evaluation
- These allocations must be preserved between function calls as they contain constant string data
- String pointers in constant memory reference this area
- Preserved Structs: Data structures that need to persist between engine ticks
- Currently unused but reserved for future use
- Stack Space: Frame-placed variables and function call frames
- Grows upward with each function call
- Reset on function entry/exit
- Heap: Dynamic allocations during program execution
- Reset after each tick to prevent memory leaks
- Starts after the preserved area to avoid corrupting constant data
Fields§
§stack_memory_size: usize§stack_offset: usize§stack_start: usize§heap_start: usize§heap_alloc_offset: usize§constant_memory_size: usize§execution_mode: ExecutionMode§debug: MemoryDebugImplementations§
Source§impl Memory
impl Memory
pub fn new( constant_memory: &[u8], stack_memory_size: usize, heap_memory_size: usize, ) -> Self
pub fn reset_offset(&mut self)
pub fn reset(&mut self)
pub fn reset_allocator(&mut self)
pub fn reset_stack_and_fp(&mut self)
pub fn set_heap_directly_after_constant_area(&mut self)
pub fn incorporate_heap_into_constant_area(&mut self)
pub fn alloc_before_stack( &mut self, size: &MemorySize, alignment: &MemoryAlignment, ) -> HeapMemoryRegion
pub fn get_heap_ptr(&self, offset: usize) -> *mut u8
pub fn get_heap_const_ptr(&self, offset: usize) -> *const u8
pub unsafe fn get_heap_offset(&self, ptr: *const u8) -> u32
pub fn heap_allocate_secret(&mut self, size: usize) -> u32
pub fn heap_allocate_with_data(&mut self, data: &[u8]) -> u32
pub fn frame_offset(&self) -> usize
Sourcepub const fn set_fp_from_sp(&mut self)
pub const fn set_fp_from_sp(&mut self)
Usually called on a call It sets the FP to the current SP. The stack pointer includes the current function frame size but doesn’t include return values and arguments.
pub fn frame_ptr(&self) -> *mut u8
pub fn get_frame_ptr_as_u32(&self, offset: u32) -> *mut u32
pub fn get_frame_ptr_as_u16(&self, offset: u32) -> *mut u16
pub fn get_frame_ptr(&self, fp_offset: u32) -> *mut u8
pub fn get_frame_const_ptr(&self, fp_offset: u32) -> *mut u8
pub fn get_frame_ptr_as_i32(&self, some_addressing: u32) -> *mut i32
pub fn get_frame_const_ptr_as_i32(&self, addressing: u32) -> *const i32
pub fn get_frame_const_ptr_as_u32(&self, offset: u32) -> *const u32
pub fn get_frame_const_ptr_as_u16(&self, addressing: u32) -> *const u16
pub fn read_frame_i32(&self, offset: u32) -> i32
pub fn read_frame_u8(&self, offset: u32) -> u8
pub fn read_frame_bool(&self, offset: u32) -> bool
pub fn read_frame_u16(&self, offset: u32) -> u16
pub fn read_frame_u32(&self, offset: u32) -> u32
pub const fn get_stack_const_ptr(&self, stack_offset: usize) -> *const u8
pub fn read_heap_offset_via_frame(&self, frame_offset: u32) -> u32
pub fn get_heap_ptr_via_frame(&self, frame_offset: u32) -> *mut u8
pub fn get_heap_u32_ptr_via_frame(&self, frame_offset: u32) -> *mut u32
pub fn get_heap_ptr_via_frame_with_offset( &self, frame_offset: u32, heap_ptr_offset: u32, ) -> *mut u8
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Memory
impl RefUnwindSafe for Memory
impl !Send for Memory
impl !Sync for Memory
impl Unpin for Memory
impl UnwindSafe for Memory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more