I am looking for the formulas to find the memory location of an element in a 3-D Array for row major and for column major. After using my logic I end up with the following formulas.
say array is A[L][M][N]
.
row-major:Loc(A[i][j][k])=base+w(M*N(i-x)+N*(j-y)+(k-z))
column-major:Loc(A[i][j][k])=base+w(M*n(i-x)+M*(k-z)+(j-y))
where x, y, z are lower bounds of 1st(L) 2nd(M) and 3rd(N) index. I tried this formula and got the correct result but when I applied this formula on a Question in the book then the answer did not match. Please can anyone help me out with this.
In a single dimensional array the address of an element of an array say A[i] is calculated using the following formula Address of A[i]=B+W∗(i–LB) where B is the base address of the array, W is the size of each element in bytes, i is the subscript of an element whose address is to be found and LB is the Lower limit / ...
Similarly, you can declare a three-dimensional (3d) array. For example, float y[2][4][3]; Here, the array y can hold 24 elements.
Accessing elements in the 3D array is similar to any other array, by using the index of the element. We have to use three loops to access all the elements inside the array x[2][1][0]. For higher dimension arrays like 4, 5, 6, etc., the concept is quite similar, but the complexity of handling the things increases.
Address of
A[I, J, K] = B + W * [(D - Do)*RC + (I - Ro)*C + (J - Co)]
Address of
A[I, J, K] = B + W * [(D - Do)*RC + (I - Ro) + (J - Co)*R]
Where:
Right one is:
row-major:Loc(A[i][j][k])=base+w(N*(i-x)+(j-y)+M*N(k-z))
column-major:Loc(A[i][j][k])=base+w((i-x)+M*N(k-z)+M*(j-y))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With