Announcement

Collapse
No announcement yet.

Multidimensional UDT Array Pointer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Multidimensional UDT Array Pointer

    Alright I have been using the DIM ... AT to create a pointer array to allow a DLL to read and change Array data from my main program.

    This works great, except when I tried doing it with a Multidemsional UDT Array (although the UDT probably has nothing to do with it).

    Here's an example:

    DLL Code:
    Code:
    GLOBAL MyArray() AS MyUDT
    
    SUB LinkArray ALIAS "LinkArray" (BYREF ArrayPtr AS MyUDT, BYVAL ArrayCnt AS LONG) EXPORT
         REDIM MyArray(1 TO 3, 1 TO ArrayCnt) AS MyUDT AT VARPTR(ArrayPtr)
    END SUB
    Program Code:
    Code:
    LinkArray MyArray(1,1), 3
    For some reason every array element in my DLL is the same as value as MyArray(1,1). I've tried MyArray(0) and MyArray(0,0), which as expected don't work at all. Do I have to pass the Array differently if its multidimensional? Or do I need to handle it in the DLL different?
    Thank you,
    Ryan M. Cross

    #2
    I don't like the fact you are redimming the array to which you passed a reference.

    Presumably myarray() was a "real" array when you filled it (code not shown), but now you are now trying to redefine it as an absolute (a "DIM AT") array?

    You should also be testing the system ERR variable in your sub following the REDIM.

    What you doing does not make any sense.... why REDIM a real array you already have as an absolute array? (which, if it is allowed, should not be IMNSHO). (You should know f it's allowed as soon as you check ERR after the REDIM).

    FWIW, there's no reason you cannot create multi-dimensional absolute arrays... but you do need to pay attention to the organization of the underlying data in memory.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


      #3
      Well I'm an idiot. My pseudo-code I wrote above does work, but I did not write it correctly in my actual code.

      Getting back the REDIM. I have always used this method before and I never found it to be a problem, but if there's a better way I would be happy to do it.

      Maybe someone from PB staff could answer if REDIM would actually cause any problems or not in a case like this.
      Thank you,
      Ryan M. Cross

      Comment


        #4
        If you want an official answer, you'll have to contact support.

        But I still don't understand what you are doing: Why 'REDIM myarray() AT' when you have already REDIMed 'myarray()' as a 'real' array, with the compiler managing the underlying memory?

        And I don't understand why the REDIM AT of 'myarray()' is NOT first ERASEing the "Real Array" of the same name before allowing you to re-define the symbol "myarray()" as an absolute array.

        Would not be surprised if that "support" isn't teminated in some future version of the compiler, especially after I send in a bug report on it after I test it and verify what is happening.

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


          #5
          Originally posted by Michael Mattias View Post
          And I don't understand why the REDIM AT of 'myarray()' is NOT first ERASEing the "Real Array" of the same name before allowing you to re-define the symbol "myarray()" as an absolute array.
          As the F1 help says,
          The AT address clause indicates the array is to be an absolute array. Absolute arrays are not reset by the REDIM statement, nor are they reset when the Sub/Function/Method/Property exits, but they can be reset with the RESET statement. See the discussion in the DIM topic for more information on absolute arrays.
          Code:
          GLOBAL MyArray() AS MyUDT
          just sets the scene for dimensioning (by DIM or REDIM) the array to be mapped at the AT address supplied.

          I use this lots.

          I don't use multi-dimensional arrays though - my brain is just not up to it. Instead, I calculate the subscript to a 1D array, so if there is an array of rows x columns, my index for row n, col m would be n*maxcolumns + m. Rows and columns starting at zero, of course.

          Comment


            #6
            Oh, phooey, I never noticed that the REDIM is done in a different module, meaning the symbol name is NOT duplicated. End confusion.

            He's just setting up to modify the array created in main.exe using functions in a DLL.

            So why not just pass the array as a parameter? You are looking at the same elements anyway!

            i.e. in your DLL
            Code:
            #COMPILE DLL 
            FUNCTION  DoSomething (myarray() AS  MyUdt)  EXPORT AS LONG 
            
               operate ion MyArray() here 
            
            ...
            
            #COMPILE EXE 
            
               CALL DoSomething (myArray())
            Sheesh, talk about the long and winding road!

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment

            Working...
            X
            😀
            🥰
            🤢
            😎
            😡
            👍
            👎