Announcement

Collapse
No announcement yet.

RESET, what is the good syntax to use?

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

  • RESET, what is the good syntax to use?

    What is the good syntax to use RESET in this "User-Defined type" piece of code?

    Code:
    TYPE RECT
      nLeft AS LONG
      nTop AS LONG
      nRight AS LONG
      nBottom AS LONG
    END TYPE
    
    TYPE ZIMAGEPROP
        hWnd        AS LONG
        anchor      AS LONG
        rc          AS RECT
        TiledBitmap AS LONG
        order       AS STRING * 2048 
        ordersize   AS LONG
        
        WMBit(25)   AS LONG          '//4.02
        WMCodePtr(25*32) AS DWORD    '//4.02
    END TYPE
    
    FUNCTION PBMAIN
    
        DIM WinProp(1 TO 10) AS ZIMAGEPROP
    
        WinProp(1).WMBit(5) = 100
    
        RESET WinProp(1).WMBit() ' <-------------
    
    END FUNCTION
    Thank you
    Patrice Terrier
    www.zapsolution.com
    www.objreader.com
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

  • #2
    Assuming you want the elements RESET to NULL?

    I'd either just do a FOR NEXT to set the individual table (not array) elements to zero...
    Code:
     FOR I = 1 TO 25 
       inProp(1).WMBit(I) = 0&
       ' or RESET WinProp(1).WmBit(I) 
     NEXT
    .. unless I were in an expansive mood, in which case I'd just use the FillMemory function / macro in Win32API.INC with ....
    Code:
      Fillmemory BYVAL VARPTR (WinProp(1).WmBit(1)), 25& * 4&, 0?
      ' 25*4 = number of table elements times  SIZEOF(LONG), a syntax not (yet?) supported
    ... after of course, trying...
    Code:
      RESET WmProp(1).WmBit
    .. even though I doubt that would work..... and when it didn't I might use a RESET of an absolute array ...
    Code:
        REDIM   X (25) As LONG AT VARPTR (WmProp(1).WmBit(1)) 
        RESET   X ()
        ERASE   X ()
    .. or maybe a loop with a pointer...
    Code:
     LOCAL pL AS LONG PTR 
     
     pl = VARPTR (WmProp(1).wmBit(1)
     FOR Z = 1 TO 25   ' 25 = number of table elements
        @pl = 0&
         INCR pl
     NEXT
    Fielder's choice if you ask me.

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

    Comment


    • #3
      Thanks Michael,

      I know how to do this "the hard way", but my point was:
      how to do it using RESET, that should be the easy way using the good syntax

      ...
      Patrice Terrier
      www.zapsolution.com
      www.objreader.com
      Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

      Comment


      • #4
        "The hard way" usually translates to "the slow way," but I tried a couple techniques and got it down to < 7 ticks per array element reset. It's not too much code, but it is more than a simple RESET, which I was unable to apply in this situation.

        Code:
        #COMPILE EXE
        #DIM ALL
                                       
        TYPE RECT
          nLeft AS LONG
          nTop AS LONG
          nRight AS LONG
          nBottom AS LONG
        END TYPE
        
        TYPE ZIMAGEPROP
            hWnd        AS LONG
            anchor      AS LONG
            rc          AS RECT
            TiledBitmap AS LONG
            order       AS STRING * 2048
            ordersize   AS LONG
        
            WMBit(25)   AS LONG          '//4.02
            WMCodePtr(25*32) AS DWORD    '//4.02
        END TYPE
        
        FUNCTION PBMAIN () AS LONG
            LOCAL ii, x AS LONG
            LOCAL resetString AS STRING
            DIM WinProp(0 TO 31) AS ZIMAGEPROP
            
            resetString = STRING$((25 + 1) * 4, 0)               '26 elements in WMBit(25), each 4 bytes (LONG)
            
            FOR ii = 1 TO 5
               x = ii AND 31                                     'don't let x get too big (for long test loops)
               WinProp(x).WMBit(0) = 1
               WinProp(x).WMBit(25) = 26
               
               ? STR$(WinProp(x).WMBit(0)) & $CRLF & STR$(WinProp(x).WMBit(25))  'remove to test for speed
               
                POKE$ VARPTR(WinProp(x).WMBit(0)), resetString   '~170 ticks to RESET 26 LONG array elements is ~7 ticks / element
                
               ? STR$(WinProp(x).WMBit(0)) & $CRLF & STR$(WinProp(x).WMBit(25))  'remove to test for speed
            NEXT
        '   RESET WinProp(1).WMBit() ' <-------------
           ? "Done"
        END FUNCTION

        Comment


        • #5
          Thanks both of you.

          Thus currently there is no RESET syntax to do that...

          ...
          Patrice Terrier
          www.zapsolution.com
          www.objreader.com
          Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

          Comment


          • #6
            >but my point was: how to do it using RESET..

            Well, that's a different question than what I read.

            The answer to the question of how to use any PowerBASIC keyword, verb or function is "look in the help file."

            If the answer is not found in the help file, contact PB support, both for an answer and to report the documentation deficiency.

            (BTW, what I did was NOT "the hard way" at all!)
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Got it down to ~5 ticks per element, if it's an even number of elements in WMBit() like your example shows. No string setup is required. Main code below. Yes, I did try a bunch of permutations of RESET, well, I don't think I can say it better than Michael: "even though I doubt[ed] that would work..... and when it didn't" I gave it a shot to be nearly as fast.

              Code:
              FUNCTION PBMAIN () AS LONG
                  LOCAL ii, ii2, x AS LONG
                  DIM WinProp(0 TO 31) AS ZIMAGEPROP
                  
                  FOR ii = 1 TO 10'000000
                     x = ii AND 31
                     WinProp(x).WMBit(0) = 1
                     WinProp(x).WMBit(25) = 26
                     
                     ? STR$(WinProp(x).WMBit(0)) & $CRLF & STR$(WinProp(x).WMBit(25))                  'remove to test for speed
                     x = VARPTR(WinProp(x).WMBit(0))
                     FOR ii2 = 0 TO 96 STEP 8 '96 = (25 + 1) * 4 - 8. That is, (WMBit() size + 1) * len LONG - len QUAD
                        POKE QUAD, x + ii2, 0   '~130 ticks to RESET 26 LONG array elements is ~5 ticks / element
                     NEXT
                     ? STR$(WinProp(ii AND 31).WMBit(0)) & $CRLF & STR$(WinProp(ii AND 31).WMBit(25))  'remove to test for speed
                  NEXT
              '    RESET WinProp(1).WMBit() ' <-------------
                 ? "Done"
              END FUNCTION

              Comment


              • #8
                I'm glad to see you were able to speed that up. Wow, 5 ticks per element.

                When you think about how significant that can be and do the math... wow again.

                Let's just say (generously) you cut the time in half from what I did off the top of my head. You have saved me 130 ticks per refresh of all 26 wmbit elements of a ZIMAGEPROP element.

                If I had a 1 Ghz processor, I would save one whole minute for every 460,000,000 times I had to refresh that ZIMAGEPROP UDT.

                But I have a 3 Ghz processor, so it will take me three times as long - 1,380,000,000 refreshes- to save that one minute.

                What luck, I was going to do 1,380,000,000 of those this afternoon. And as luck would have it futher, since I like to have a couple of cups of coffee while working I have just the place to spend that saved minute.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Remember tho, you get the full minute only if it's an even number of elements in WMBit(). Also I think you meant a cup of coffee in that free time, not a couple. Caffeine overdose can really cause the jitters.

                  Comment


                  • #10
                    A minute a day will keep the Dr. away

                    MCM...cmon, sure shaving minuscule amount of time only helps when it adds up. But if it all works as expected then in your own words shaving this time is "Application Specific"


                    (by the way...you may want to shave a few coffee's off before you jitter and bounce like me by the end of the day )
                    Engineer's Motto: If it aint broke take it apart and fix it

                    "If at 1st you don't succeed... call it version 1.0"

                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                    Comment


                    • #11
                      >Also I think you meant a cup of coffee in that free time, not a couple.

                      Um, Cliff, the minute will be used for the OUTPUT side of drinking coffee, not the input side.

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

                      Comment

                      Working...
                      X