Announcement

Collapse
No announcement yet.

Assign string array

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

  • Assign string array

    Hi all,
    Does anyone know of a quick way to assign all the data from one string array to another (maybe in assembler), at the moment I am using a FOR\NEXT loop, but it is quite slow on large arrays.

    The arrays are identical in length.

    Thanks,


    -------------
    Kev G Peel
    KGP Software
    Bridgwater, UK.
    mailto:[email protected][email protected]</A>

  • #2
    In lieu of resorting to inline assembler code, the API "RtlMovememory" (MoveMemory) should work.

    Search the Topics. This has probably been discussed before.

    Comment


    • #3
      PB/Win 32 uses OLE strings; correct? And the array itself physically holds OLE string handles; correct? (I *think* that's correct, anyway).

      If so (and I may be way off base here), can't you just

      DIM NewArray(size) AT VARPTR(OldArray()) AS STRING

      .. and now NewArray is working on the same data? That is, changing one changes the other, but you may now refer to the data by either name?

      This is not the same as copying, but I thought I'd ask (i.e., I'm getting lazy in my old age and don't feel like testing it today).

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

      Comment


      • #4
        The PB RTL & OLE string engine handle the allocation and storage of the actual dynamic string data (you can check the address of the actual data if you use STRPTR()). The location of the string data itself will change as the string data is changed/manipulated during normal program execution - however, it does not change unless the string data is altered.

        Therefore, the problem is that there is no way to guarantee that the actual string data (in a dynamic string array) will be stored sequentially in memory, hence there is no simple way to be able to read the data within a whole dynamic string array in one go.

        In addition, the string engine also adds an additional NULL byte to each string in memory, and this would have to be taken into account (this is also true for other PB string types).

        The simple answer is that if you are using a dynamic string array, you'll have to loop through each array element to duplicate the string array - there is no simple workaround.

        However, if you use a fixed-length or asciiz string array, you'll find that the string data occupies a fixed location in memory, so it is possible to duplicate an entire array with a pair of POKE$ and PEEK$ functions - it can be supprisingly simple:

        Code:
        ' PBCC code, to show technique
        FUNCTION PBMAIN
            DIM a(1:10) AS STRING * 10, b(1:10) AS STRING * 10
            FOR x& = 1 TO 10
                a(x&) = FORMAT$(x&, "##########")
            NEXT x&
            POKE$ VARPTR(b(1)), PEEK$(VARPTR(a(1)), UBOUND(a(1)) * (SIZEOF(a(1)) + 1))
            FOR x& = 1 TO 10
                PRINT x&, $DQ b(x&) $DQ
            NEXT x&
            WAITKEY$
        END FUNCTION
        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          OK thanks lance, thats all I wanted to know.
          Looks like I will have to stick with FOR\NEXT because the array isn't fixed length.

          Regards,

          ------------------
          Kev G Peel
          KGP Software
          Bridgwater, UK.
          mailto:[email protected][email protected]</A>

          Comment

          Working...
          X