2 ms·
Yes. I would caution on inserting stack objects into shared lists, though, because it's such an easy footgun if the reference outlives the stack frame.
by loeg 5y ago
Yes. I would caution on inserting stack objects into shared lists, though, because it's such an easy footgun if the reference outlives the stack frame.
- Matthias247 5y agoIt's not really worse than heap allocated objects. For them you also need to make sure the pointer in the list does not outlive the actual object. The only safe structures are heap allocated plus reference counted ones, where inserting something into a list also increments the refcount.
- loeg 5y agoI think you're completely correct, in a pedantic sense. However, heap object lifetimes aren't bound to control flow in quite the same way.