+ 1
Are indexes faster or pointers which one is faster?
2 Antworten
+ 4
Depends on what we are talking about. If we are talking about using heap memory and stack memory is not that pointers will be slower but heap memory is slower but more flexible than stack.
If we are talking about using pointer for making loops. Or using for pass a value or store. Sure pointers will be faster.
But we need to remember 3 important things about when we wanna discuss pointer vs indexes
and optimization.
1)Generally the compiler "read"your code and make a lot o optimization.
2) This optimizations with the modern CPU's speed will make you won't notice any difference. Practically you will need to do billion of times this operations to notice some difference.
3) Programming for embedded platforms or any application that needs extremely performance, you need to do optimizations for your own. So is nice to know what is faster in this case.
+ 4
Index is only a syntactic sugar for pointer arithmetic. For example,
array[5] == *(array + 5)
There's no performance penalty for choosing either of then to perform the indexing operation. The language design usually provides different way of doing the same thing with different formats. Just some of them are easier to work with than others.
_____
https://en.m.wikipedia.org/wiki/Syntactic_sugar