Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> keeping the values in a Box<T> > for keeping a value in more than one collection would be to use a Rc<T>

Indeed, both methods are simple and elegant ways to approach the problems.

The bad thing with both of them is performance.

Box<T> means when I need to iterate through all values in a collection, I’ll get random memory access for each item. Rc<T> is even worse, not only it’s RAM read latency per item, also ref.counting overhead per item (AFAIK even when reading stuff).



> also ref.counting overhead per item (AFAIK even when reading stuff).

That's the beauty of the borrow checker: no, there's no reference counting overhead when reading stuff. The borrow checker guarantees that the reference you used to access the value won't go away until you're done with it, so it doesn't have to increment the reference counter.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: