|
|
|
|
|
by lnggahc
691 days ago
|
|
> It's impossible to write complex and performant programs without null. Well, clearly there is a need for a special value that is not part of the set of legal values. Things like std::optional etc. are of course less performant. If I can dream, all of this would be solved by 72-bit CPUs, which would be the same as 64-bit CPUs, but the upper 8 bits can be used for garbage collection tags, sentinel values, option types etc. |
|
There's a neat trick available here: If you make zero an illegal value for the pointer itself, you can use zero as your "special value" for the std::optional wrapper, and the performance overhead goes away.
This is exactly what Rust does, and as a result, Option<&T>, Option<Box<T>>, etc are guaranteed to have zero overhead: https://doc.rust-lang.org/std/option/index.html#representati...