I wonder if there is a way to find out if a variable stack or heap is selected.
Consider this:
struct SomeStruct;
fn main() {
let some_thing = Box::new(SomeStruct);
println!("{:p}", some_thing);
foo(&*some_thing);
}
fn foo (bar: &SomeStruct) {
println!("{:p}", bar);
}
prints
0x1
0x1
And then
struct SomeStruct;
fn main() {
let some_thing = &SomeStruct;
println!("{:p}", some_thing);
foo(some_thing);
}
fn foo (bar: &SomeStruct) {
println!("{:p}", bar);
}
prints
0x10694dcc0
0x10694dcc0
I see that the memory address is much shorter for a dedicated heap version, but I don't know if this is a reliable way to tell the difference. I wonder if there is something likestd::foo::is_heap_allocated()
source
share