Module heap_ops

Source
Expand description

§Heap Operations Handler

Handles all heap memory operations in the VM including object and array allocation, property access, and memory management.

§Operations Supported

  • Allocation: alloc_object, alloc_array, alloc_function, alloc_string
  • Object Operations: get_object_property, set_object_property, remove_object_property
  • Array Operations: get_array_element, set_array_element, push_array_element
  • Memory Management: get_heap_size, is_heap_empty, clear_heap, collect_garbage
  • Statistics: get_heap_stats, get_heap_metrics
  • Utilities: clone_heap_entry, deallocate

§Memory Management

  • Automatic Allocation: Objects and arrays are automatically allocated
  • Reference Counting: Uses reference counting for memory management
  • Garbage Collection: Automatic cleanup of unused objects
  • Memory Safety: Prevents memory leaks and invalid access

§Usage

use jetcrab::vm::executor::instruction_handlers::HeapOpsHandler;
use jetcrab::vm::executor::traits::{StackOperations, HeapOperations};

let mut stack = MyStack::new();
let mut heap = MyHeap::new();
HeapOpsHandler::alloc_object(&mut stack, &mut heap)?;
// Stack now contains: [ObjectHandle]

Structs§

HeapOpsHandler
Handles heap operations for the VM