3 ms·
> 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
by lnggahc 2y 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.
- dwattttt 2y ago> 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. https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/cheri-morello.html https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/cheri... Address space is 64bit, pointers are 128bit, and encode the region the pointer is allowed to dereference. And there's a secret 129th bit that doesn't live in the address space that gets flipped if the pointer is overwritten (unless it's an explicit instruction for changing a pointer)
- sapiogram 2y ago> Well, clearly there is a need for a special value that is not part of the set of legal values. 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#representation https://doc.rust-lang.org/std/option/index.html#representati...