Using alloc
with the SRAM?
#308
Replies: 5 comments 1 reply
-
You are already using the SRAM because your program stack and data is located there. The concept of a HEAP does not really exist at this point (or on plain embedded platforms in general). Depending on what you want to do, that's not even something you need - many embedded applications work quite fine without one and in doing so circumvent a large number of problems. As an alternative, you can push things you'd usually allocate on the heap into a static mut VAR: Option<TYPE> = None;
// initialize it
unsafe { VAR = Some(value); }
// get an &mut reference to it (will panic if not initialized)
let var_ref = unsafe { VAR.as_mut().unwrap() }; Of course this needs unsafe for a reason - there are a few invariants you must uphold here. On the other hand, it is possible to make To make it work, you must first define a "heap" by defining a large buffer as a |
Beta Was this translation helpful? Give feedback.
-
Is there a example for using vectors or alloc? |
Beta Was this translation helpful? Give feedback.
-
I don't think so. But as stated above, just set up |
Beta Was this translation helpful? Give feedback.
-
Can you give me a example? I couldn't find any examples or docs available |
Beta Was this translation helpful? Give feedback.
-
Don't have an example available, but really just follow the static mut HEAP: [u8; 1024] = [0u8; 1024];
#[global_allocator]
static ALLOCATOR: LockedHeap = LockedHeap::empty();
fn main() {
unsafe {
let heap_start = HEAP.as_ptr() as usize;
let heap_size = HEAP.len(); // or core::mem::size_of(HEAP);
ALLOCATOR.lock().init(heap_start, heap_size);
}
} (I have never tried this on AVR though, so I cannot guarantee that it works there) |
Beta Was this translation helpful? Give feedback.
-
Hey there! I tried toying with this but I'm unsure if its because it isn't implemented yet. There is RAM on the Arduino that can be used. For example 2,048 bytes for the Uno. How can I access this through the library?
Beta Was this translation helpful? Give feedback.
All reactions