Skoči na glavni sadržaj

Izvorni znanstveni članak

https://doi.org/10.31341/jios.48.1.3

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

Robert Logožar ; Dpt. of Electrical Engineering, University North, Varaždin, Croatia
Matija Mikac orcid id orcid.org/0000-0002-3449-8607 ; Dpt. of Electrical Engineering, University North, Varaždin, Croatia
Danijel Radošević ; Faculty of Organization and Informatics, University of Zagreb, Varaždin, Croatia


Puni tekst: engleski pdf 1.124 Kb

verzije

str. 49-80

preuzimanja: 0

citiraj


Sažetak

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.

Ključne riječi

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

Hrčak ID:

317974

URI

https://hrcak.srce.hr/317974

Datum izdavanja:

16.6.2024.

Posjeta: 0 *