1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Memory address of 3D array

  1. Oct 24, 2013 #1
    1. The problem statement, all variables and given/known data

    The problem is finding the memory location of a three-dimentional array Temp. Each index of temp goes from 1 to 100 and each element stores 4 bytes. The array is setup such that the last index varies fastest, aka:

    Temp[1,1,1], Temp[1,1,2], ... Temp[1,1,100], Temp[1,2,1]
    Temp[1,100,100], Temp[2,1,1], ... Temp[2,1,2], ... Temp[2,1,100], Temp[2,2,1], ... Temp[100,100,100]

    Find the address of the array Temp[40,30,20]

    2. Relevant equations

    I know that For a three-dimensional array, the formula to compute the offset into memory is the following:

    Address = BaseAddress + ((depthindex*col_size+colindex) * row_size + rowindex) * Element_Size

    Attempted work

    for the array Temp[40,30,20]

    Address = BaseAddress + ((depthindex*col_size+colindex) * row_size + rowindex) * Element_Size

    BaseAddress = m
    Element_size = 4 bytes
    Col_size = 100
    Row_size = 100

    Depthindex = 40
    Colindex = 30
    Rowindex = 20

    Address = m + ( (40*100 + 30)*100 + 20 ) * 4 bytes
    = m + ( (4030)*100 + 20 ) * 4 bytes
    = m + (403020) * 4 bytes
    = m + 1612080


    Am I on the right track, here?

    Thanks so much!
     
  2. jcsd
  3. Oct 24, 2013 #2

    rcgldr

    User Avatar
    Homework Helper

    Looks ok to me.
     
  4. Oct 25, 2013 #3
    Except that you're placing your first element off your starting address:

    Address Temp[1,1,1]
    Address = BaseAddress + ((1*100+1)*100+1)*4 = BaseAddress + 40404

    we expected it to be BaseAddress, right?

    Hint: that equation would be corrected if the indexes started at 0; as they start at 1 you need to.... for each index in the formula
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Memory address of 3D array
  1. Address Decoder (Replies: 1)

  2. Address Formats (Replies: 6)

Loading...