Useful Rust knowledge:
An enum always takes up the space in memory occupied by its largest member + a discriminant (which is often optimized away, though).
This means:
For an Option<T>, every None takes up at least the same space as the T wrapped by the Option.
An enum always takes up the space in memory occupied by its largest member + a discriminant (which is often optimized away, though).
This means:
For an Option<T>, every None takes up at least the same space as the T wrapped by the Option.
This also means:
A Vec<Option<T>> might be a pretty bad idea if the majority of items will always be None.
That's a huge waste of memory and requires other data structures if memory is a constraint in your software.
A Vec<Option<T>> might be a pretty bad idea if the majority of items will always be None.
That's a huge waste of memory and requires other data structures if memory is a constraint in your software.
Why is this relevant?
Rust is a systems programming language close to the metal.
Such details matter in Rust.
I would also ask questions about this in interviews when I hire Rust engineers.
Rust is a systems programming language close to the metal.
Such details matter in Rust.
I would also ask questions about this in interviews when I hire Rust engineers.
Additionally:
Even application-level software you write in Rust does often not have infinite memory available.
Optimizing a few things here and there can usually bring cloud bills down by a lot, and things like memory optimization do help with this.
Even application-level software you write in Rust does often not have infinite memory available.
Optimizing a few things here and there can usually bring cloud bills down by a lot, and things like memory optimization do help with this.
Loading suggestions...