3 ms·
I think it is debatable on whether struct property access and pointer access should appear the same. * Performance. Pointer access is an order of magnitude mor
by paulddraper 3y ago
I think it is debatable on whether struct property access and pointer access should appear the same.
* Performance. Pointer access is an order of magnitude more expensive.
* Errors. Pointer access can fail (in particular, the NULL pointer).
- WalterBright 3y agoIt may be debatable, but in D we've used it for 20 years and problems with it have yet to crop up. And indeed, it makes refactoring code far easier.
- paulddraper 3y agoNot directly to syntax, but D null pointer safety is weird IMO. It checks array access bounds, but segfaults for null pointers. Seems an odd choice, and there are multiple discussions of people saying the same.
- WalterBright 3y agoNull pointers are automatically checked by the hardware (seg fault). Adding another runtime check is redundant. Yes, I know, adding a huge fixed offset to the pointer can push it past the null protected pages.
- brundolf 3y agoRust makes them the same too (though its type system eliminates the fallibility issue)
- _3u10 3y agoThe stack is not some magical location in RAM that is faster, and in any case you can have a pointer to the stack. It's super common to define a struct on the stack and then pass a pointer to an init function to initialize the value that is on the stack. Sometimes pointers are faster because you don't have to copy the entire struct. What largely determines the performance of values vs. pointers is whether that location in RAM is cached, and whether you need to allocate memory on the heap.