Comments by "MrAbrazildo" (@MrAbrazildo) on "Zig is FASTER and SAFER than Rust | Prime Reacts" video.
-
1:50, those 2 are meant for big fat resources only. But there's a lot of memory accessing in which you can earn performance through pointers. Some days ago, I was optimizing a small project, and tried a bunch of algorithms, for passing data from string to an array. Using pointers (iterators actually) was the fastest, making the whole app 10x faster than using the slowest, sscanf() from C.
7:30, in C/C++ it's not undefined behaviour, as long as I know. It only will loose performance. There's a tool from Clang compiler that shows where/when it looses that in the code.
8:55, he said that this pointer usage was an attempt to turn around borrow checker rules.
9:25, undefined behaviour is the sum of all fears in coding, because it doesn't grant to obey rules anymore, from that point. It means that, for instance, if you test your code, it won't execute it, when you read an array, it may read after its end, and things like that. So your project will crash sometimes and work on other tries!
11:30, to take away an argument in C/C++ macros, it's needed to redefine it:
#define ptr__field (*ptr).field
But gonna need to do that for the entire class (all fields), multiplied by each different pointer name!
1
-
26:00, I don't even remember when I had some serious issue, regarding to pointer indexing in C++. I wrote a class that inherits a container, and checks the index. I can turn that on/off anytime, for the entire project, by changing just 1 line!
It's also hard to get a trouble about pointer dereferencing, because everything is 'begin() + K, end() - N', valid range of containers. There's no space here for pointer issue. And when I send a nullable pointer to a f(), it uses to be null by default, which means I want to give the user the choice of sending it or not. In this context, it's obvious that I'll check the pointer soon. If it's a 'const char *' (for a string literal), and I want to earn some performance by not checking it, I set its default to "". So I don't have issues with pointer at all!
28:39, he meant that failing on those checks forced him to give up on pointers. These are much faster, because indexing always come all the way from the beginning. And failing to UB is not an option.
1