| ▲ | vinkelhake 2 hours ago | |||||||
These seem like some fairly standard approaches for reducing memory usage. I can't help to think that the approach of joining several distinct list into a single one in some way undercuts Rust's safety guarantees. If you previous had three distinct Vec objects, then Rust would guarantee that you can't index out of bounds. If you now put all those objects into a single Vec and rely on offsets, then you now open the door to indexing out of range of these sub-slices without any panics. It's a minor point, and it doesn't really invalidate the optimization, but I'm surprised the article didn't mention it. | ||||||||
| ▲ | ratorx 2 hours ago | parent | next [-] | |||||||
I think it’s more of a time vs code tradeoff, if done properly. For example in the Vec case, you could theoretically build an alternative which encodes the “three sections” property internally, and ensures correctness at construction time for the pointers. Not as completely safe as a Vec, but you can still get similar benefits for the “business logic”. But I agree, just having a custom structure that does not provide a safe wrapper around this would be sacrificing standard guarantees. | ||||||||
| ▲ | vsgherzi 2 hours ago | parent | prev | next [-] | |||||||
you could always do a .get into the vector and handle the error, it doesn't necessarily need to panic. Thank being said in this case it should be impossible to index out of bounds so maybe a panic is warented. | ||||||||
| ▲ | FpUser 2 hours ago | parent | prev [-] | |||||||
Tools exist to serve us, not the other way around. | ||||||||
| ||||||||