Announcement

Collapse
No announcement yet.

An ARRAY of ASCIIZ STR PTR - Is this possible?

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

  • An ARRAY of ASCIIZ STR PTR - Is this possible?

    I am trying to speed up my code.
    My DLL is passed an ASCIIZ STR PTR for the text I want to manipulate. This text is long and gets sent all over the place so I want to use pointers to avoid moving thousands of characters on many lines each time.
    so heres what i have (snippet) ...

    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
    FUNCTION LibMain(BYVAL hInstance AS LONG, _
    BYVAL fwdReason AS LONG, _
    BYVAL lpvReserved AS LONG) EXPORT AS LONG
    SELECT CASE fwdReason
    CASE %DLL_PROCESS_ATTACH ' DLL loads
    DIM TStext(20) AS GLOBAL ASCIIZ PTR
    CALL MakeWindow ' Create Main Dialog Window
    Blah
    Blah
    Blah
    END FUNCTION
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION Stepper(BYVAL StopFlag AS DWORD,_
    BYVAL CurrentBar AS SINGLE,_
    BYVAL FinalBar AS DWORD,_
    BYVAL SentNumBars AS SINGLE,_
    TextPtr AS ASCIIZ PTR) EXPORT AS SINGLE
    BarNum = INT(CurrentBar) ' value = 1 - FinalBar
    Blah
    Blah
    Blah
    TStext(BarNum) = TextPtr
    NumBars = NumBars + 1
    IF FinalBar = 1 THEN
    FOR i = 1 TO NumBars
    CONTROL SEND hDlg, 101, %LB_ADDSTRING, 0, TStext(i) ' update the listbox
    NEXT
    END IF
    Blah
    Blah
    Blah

    END FUNCTION









    ------------------
    Kind Regards
    Mike

  • #2
    This text is long and gets sent all over the place so I want to use pointers to avoid moving thousands of characters on many lines each time.
    When you dedine a procedure thus:

    Code:
    FUNCTION FOO (X AS ASCIIZ * 2048) AS LONG
    END FUNCTION
    and call it with:
    Code:
      J = Foo (Z)
    All you EVER pass is a pointer. "Thousands of characters" are NEVER relocated or rebuilt for any procedure call (unless you are passing something requiring conversion from Fixed/ASCIIZ to Dynamic strings or vice-versa).

    MCM


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

    Comment


    • #3
      ok so if I define 20 ASCIIZ strings with
      DIM TStext(20) AS GLOBAL ASCIIZ * 1024

      and then load it up one at a time with
      TStext(NumBar) = @SentString

      when I come to send all those strings to the LISTBOX with
      FOR i = 1 TO LastBar
      CONTROL SEND hDlg, 165, %LB_ADDSTRING, 0, TStext(i)
      NEXT

      I am only "sending" a pointer or a handle to the string?

      I have not xfer all those characters once?



      ------------------
      Kind Regards
      Mike

      Comment


      • #4
        %LB_ADDSTRING will always make a copy of your string and I don't think it would send a pointer anyway.

        Bjorge has a super Virtual listbox control in the source section that avoids
        the string copying in a listbox. It is fast and easy to extend.

        Mike


        ------------------

        Comment


        • #5
          Sorry, that is not correct.

          The SendMessage() API (which is encapsulated by the CONTROL SEND statement) will send a pointer (whose target is the string data) to the control.


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Lance is right here, from win32.hlp, the lParam of LB_ADDSTRING
            is the address of a zero terminated string.

            LB_ADDSTRING
            wParam = 0; // not used; must be zero
            lParam = (LPARAM) (LPCTSTR) lpsz; // address of string to add

            In PowerBASIC,

            SendMessage hList,%LB_ADDSTRING,0,lpszString.

            If you can get the handle of the list box in the DLL, why not
            directly load it from the SUB/FUNCTION that allocates the zero
            terminated strings so you don't have the overhead of passing
            them ? I guess it will depend on how your prog is written but
            its a lot faster to directly load it into the list box than to
            pass it as parameters on the stack.

            Regards,

            [email protected]

            ------------------
            hutch at movsd dot com
            The MASM Forum

            www.masm32.com

            Comment


            • #7
              You are right that it sends a pointer but the API then uses that pointer to make a copy of the string. Try adding string to a listbox and watch the resources drop.
              My understanding is Mike wanted to eliminate that copying in the API.


              Bjorge's routine eliminates that resource usage.

              Mike

              ------------------

              Comment


              • #8
                I think that more natural way - to use OWNERDRAWN w/o HASSTRINGS style.
                Tested under Win2000 only:
                Code:
                  #Compile Exe
                  #Dim All
                  #Register None
                  #Include "WIN32API.INC"
                
                  %ID_LIST1 = 130
                  %nEl = 1000
                  Global arr() As String
                
                  CallBack Function DlgProc
                      Select Case CbMsg
                         Case %WM_DRAWITEM
                            Local lpdis As DRAWITEMSTRUCT Ptr
                            lpdis = CbLparam
                            If @lpdis.itemID = -1 Then Exit Function
                            If IsFalse(@lpdis.itemState And %ODS_SELECTED) Then
                               FillRect @lpdis.hDC, @lpdis.rcItem, GetStockObject(%WHITE_BRUSH)
                               SetBkColor @lpdis.hDC, %WHITE
                               SetTextColor @lpdis.hDC, %BLACK
                            Else
                               FillRect @lpdis.hDC, @lpdis.rcItem, GetStockObject(%BLACK_BRUSH)
                               SetBkColor @lpdis.hDC, %BLACK
                               SetTextColor @lpdis.hDC, %WHITE
                            End If
                            TextOut @lpdis.hDC, 0, @lpdis.rcItem.ntop, ByVal StrPtr(arr(@lpdis.itemID)), Len(arr(@lpdis.itemID))
                            Function = 1: Exit Function
                      End Select
                   End Function
                
                  Function PbMain
                     Local hDlg As Long, i As Long, hList As Long
                     Dialog New 0, "Listbox", , , 100, 70, %WS_CAPTION Or %WS_SYSMENU To hDlg
                     Control Add ListBox, hDlg, %ID_LIST1, , 5, 5, 90, 65, _
                        %WS_CHILD Or %LBS_OWNERDRAWFIXED Or _
                        %WS_TABSTOP Or %LBS_DISABLENOSCROLL Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
                     Control Handle hDlg, %ID_LIST1 To hList
                     ReDim arr(%nEl - 1)
                     For i = 0 To %nEl - 1
                        arr(i) = "Item" + Str$(i)
                        SendMessage hList, %LB_ADDSTRING, i, 0
                     Next
                     SendMessage hList, %LB_SETCURSEL, 3, 0 ' Item 3
                     Dialog Show Modal hDlg, Call DlgProc
                  End Function
                ------------------
                E-MAIL: [email protected]

                Comment

                Working...
                X