ResearchBib Share Your Research, Maximize Your Social Impacts
Sign for Notice Everyday Sign up >> Login

Exploring the Access to the Static Array Elements via Indices and via Pointers — the Introductory C++ Case Expanded

Journal: Journal of Information and Organizational Sciences (JIOS) (Vol.48, No. 1)

Publication Date:

Authors : ; ; ;

Page : 49-80

Keywords : static arrays; pointers; C/C++; accessing the array elements; benchmarks;

Source : Downloadexternal Find it from : Google Scholarexternal

Abstract

We revisit the old but formally still unresolved debate on the time efficiency of accessing the elements of 1D arrays via indices versus accessing them via pointers. To analyze that, we have programmed benchmarks of minimal complexity in the C++ language and inspected the machine code of their compilation in the x86 assembly language. Before exploring the performance, we briefly compared a few methods used for the execution time measurements. The results on the Wintel platform show no significant advantage in using pointers over indices except for some benchmarks and array (data) types. In other cases, the exact opposite may be true. The cause of this inconsistency lies in the compilation of the source code into the rather nonorthogonal x86 instruction set. Furthermore, the execution speed does not clearly relate to the instruction length. The parallel aim of this work is to provide a ground for further analysis and measurements of this kind using different compilers, languages, and computer platforms.

Last modified: 2024-07-09 21:17:34