Results 1 to 2 of 2

Thread: Array.Copy on Multi Dimensional Arrays?

  1. #1

    Thread Starter
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Array.Copy on Multi Dimensional Arrays?

    Ok. 1 D arrays are pretty easy.
    For example:

    VB Code:
    1. 'somewhere...
    2. Private Declare Sub ShiftMemoryLong Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Long, hpvSource As Long, ByVal cbCopy As Long)
    3.  
    4. 'somewhere else...
    5.  
    6. Private Sub PULL_CELL(ByVal M_Spot As Long, ByVal OUT_VAL As Long)
    7.     'we don't need out_val anymore
    8.     Num_Is_Used(OUT_VAL - LowNum) = True
    9.     If M_Spot <> SlidingSourceTop Then
    10.         Call ShiftMemoryLong(SourceNums(M_Spot), SourceNums(M_Spot + 1), 4 * (SlidingSourceTop - M_Spot))
    11.     End If
    12. End Sub
    13. Private Sub PUSH_CELL(ByVal M_Spot As Long, ByRef OUT_VAL As Long)
    14.     If M_Spot <> SlidingSourceTop Then
    15.         Call ShiftMemoryLong(SourceNums(M_Spot + 1), SourceNums(M_Spot), 4 * (SlidingSourceTop - M_Spot))
    16.     End If
    17.     SourceNums(M_Spot) = OUT_VAL
    18.     Num_Is_Used(OUT_VAL - LowNum) = False
    19. End Sub

    easily converts to:

    VB Code:
    1. Private Sub PULL_CELL(ByVal M_Spot As Integer, ByVal OUT_VAL As Integer)
    2.         Num_Is_Used(OUT_VAL - LowNum) = True
    3.         If M_Spot <> SlidingSourceTop Then
    4.             Array.Copy(SourceNums, (M_Spot + 1), SourceNums, (M_Spot), (SlidingSourceTop - M_Spot))
    5.         End If
    6.     End Sub
    7.     Private Sub PUSH_CELL(ByVal M_Spot As Integer, ByRef OUT_VAL As Integer)
    8.         If M_Spot <> SlidingSourceTop Then
    9.             Array.Copy(SourceNums, (M_Spot), SourceNums, (M_Spot + 1), (SlidingSourceTop - M_Spot))
    10.         End If
    11.         SourceNums(M_Spot) = OUT_VAL
    12.     End Sub

    But how can I convert the following to Array.Copy?

    VB Code:
    1. ShiftMemoryLong MyParaLowLims(MainLev, LastLimitLift), MyParaLowLims(MainLev, LastLimitLift - 1), 4 * (MaxLev + 1 - MainLev)
    2. ShiftMemoryLong MyParaHighLims(MainLev, LastLimitLift), MyParaHighLims(MainLev, LastLimitLift - 1), 4 * (MaxLev + 1 - MainLev)


  2. #2
    Lively Member Something Else's Avatar
    Join Date
    Nov 2003
    Location
    Where Humboldt Intersects Carlson
    Posts
    99
    Alrighty.

    Array.Copy processes 2d arrays at 90 degrees to how the api ShiftMemoryRight or CopyMem technique does it.

    Array.Copy also requires the 1 dimensional mapping of a 2d or more indexing, ie... Lets say you wanted to copy to or from (a, b).

    I don't have my code handy, but you have to reference (a, b) as either a*(Length of Dimension 0) + b, or the other way, b*(Length of dimension 1) + a.

    1 More Thing. it seems that Array.Copy requires the source and destination array must have the same dimensioning. So, lets say you had a 2 d array, and all you needed was the first 10 elements of each row. CopyMem would let you do it. Array.Copy won't.

    So, Heres 1 laqst parting question.

    If I have an array:
    VB Code:
    1. Dim MyArr(,) as Integer
    2. ReDim MyArr(123,79)

    is there any way to get the one dimensional index of MyArr(93,11)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width