Array Storage

Array Storage

In this section:

There are two methods of storing arrays, row-wise and column-wise. Row-wise storage means that the elements are stored a row at a time starting from a base address and increasing towards high memory. Arrays stored column-wise have the elements stored a column at a time increasing towards high memory.

For example, consider the array consisting of 10 rows and 20 columns. The appropriate declarations in each language would be:

FTN77

INTEGER*4 numbers(10,20)

FTN95

INTEGER (KIND=3) numbers(10,20)

C/C++

int numbers[20][10];


A row-wise array would be stored as:

numbers(0,0); numbers(1,0); numbers(2,0); ... numbers(9,0);
numbers(0,1);....

whilst a column-wise array would store the elements as

numbers(0,0); numbers(0,1); numbers(0,3); ... numbers(0,9);
numbers(1,0);....

The various language standards define Fortran as using column-wise storage, whilst C/C++ stores arrays row-wise. Therefore, a Fortran array defined as numbers(10,20), would have the equivalent C/C++ declaration numbers[20][10]. In Fortran by default the elements are actually numbered from one whilst in C/C++ they are numbered from zero.

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited