Are indexes faster or pointers which one is faster? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Are indexes faster or pointers which one is faster?

28th Oct 2018, 12:09 PM
Vishal G
Vishal G - avatar
2 Answers
+ 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.
28th Oct 2018, 12:52 PM
Anya
Anya - avatar
+ 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
2nd Nov 2018, 3:44 PM
Babak
Babak - avatar