broom icon indicating copy to clipboard operation
broom copied to clipboard

docs and examples

Open peter7891 opened this issue 2 years ago • 2 comments

Can you document the differences between the types Rooted and Handle? They seem to be very similar. Maybe, also some examples of the 2 different usecases they satisfy. I have a stack VM and when i allocate a new object, i do insert on the heap and it gives back a Rooted<T>. But on the example, you are using Handle in the Object enum. Should i do rooted.into_handle()? It is unclear. It looks like, the Handle will not keep the object alive.

peter7891 avatar Jul 27 '23 23:07 peter7891

Yes, you're correct. Rooted will survive a heap clean (and acts as the 'root' of an object tree) whereas Handle will not. If you have a stack VM, items on your stack should probably be Rooted<Value>s, but references within your Value should be Handle<Value>s.

zesterer avatar Jul 31 '23 11:07 zesterer

Yes, you're correct. Rooted will survive a heap clean (and acts as the 'root' of an object tree) whereas Handle will not. If you have a stack VM, items on your stack should probably be Rooted<Value>s, but references within your Value should be Handle<Value>s.

Right. Rooted is like Rc<T> and Handle is like Weak<T>

peter7891 avatar Aug 04 '23 20:08 peter7891