0% found this document useful (0 votes)
13 views2 pages

Array Memory Mapping Math

Uploaded by

weeeabooojones
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Array Memory Mapping Math

Uploaded by

weeeabooojones
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Memory Mapping of Array

Question: Given a 2D array A[10][20], find the memory


location of A[6][15] if loc(A[0][0])=100. Assume column-
wise memory is allocated in the double type.
Solution:
Here,
l1 = 0, u1 = 9, l2 = 0, u2 = 19
b = 100, i = 6, j = 15, L = 8
M = 10, N = 20

For column major:


addr(a[i, j]) = b + (j − l2)*M*L + (i − l1)L

Hence,
addr(A[6][15]) = 100 + (15 – 0)*10* 8 + (6 – 0)*8
= 1348 (Ans)

Question: Find the memory location of A[70][60] if


loc(A[20][15])=10000. Assume row-wise memory is
allocated in the floating point type array A[80][100], where
each float data is 4 bytes.
Solution:
For row major:
addr(a[i, j]) = b + (i – l1)*N*L + (j – l2)*L

At first, we need to calculate the base for A[20][15]:

l1 = 0, u1 = 79, l2 = 0, u2 = 99
b = ??, i = 20, j = 15, L = 4
M = 80, N = 100

Hence,
10000 = b + (20 – 0)*100*4 + (15 – 0)*4
b = 10000 – 8060
b = 1940

For A[70][60]:
l1 = 0, u1 = 79, l2 = 0, u2 = 99
b = 1940, i = 70, j = 60, L = 4
M = 80, N = 100

Hence,
addr(A[70][60]) = 1940 + (70 – 0)*100*4 + (60 – 0)*4
= 30180 (Ans)

You might also like