Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 52

Thread: ARRAY-ideas

  1. #21
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,779
    Rep Power
    10
    Hi Rene,

    speed improvement of about 10x was achieved using pointers in string comparison instead of getting strings from HEAP comparing it as a string.
    I should have done some mistake or there is a string situation I was not expecting.

    Can you be so kind to send me by mail at support@thinbasic.com a zip file with all the sources giving error so I can test?

    Thanks
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #22
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    i had a link to it in the last post, but because it's you i attach the attachement for you here again

    PS. probably memory-compare could lead to the string to search for is larger than heap-size?

    PPS. start one of the testprojects to test,
    find array-scan-functions in unit GUI.tBasicU all called like t_GUI.Enum...()

    #minVersion 1.9.13.0 + thinCore.dll from september 10th
    Attached Files Attached Files
    Last edited by ReneMiner; 14-09-2014 at 10:54.
    I think there are missing some Forum-sections as beta-testing and support

  3. #23
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,779
    Rep Power
    10
    Hi Rene,

    I'm making a lot of testing but it seems that the GPF is generated not by my code but in some situation when ARRAY SCAN ... PTR does not return any index because the string was not found while the script in reality is sure the index will be valid.

    In any case, I'm not 100% sure about that: your code is very complex and I'm not able to debug till the exact point where the GPF occurs.

    I'm going on investigating.
    Eros
    Last edited by ErosOlmi; 14-09-2014 at 11:57.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #24
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    ok, i found something - seems array scan not always can find existing data when collate ucase, i made some example
    Uses "console"
    
    
    %vt_Byte      = EnumType("Byte")     As DWord
    %vt_Integer   = EnumType("Integer")  As DWord
    %vt_Word      = EnumType("WORD")     As DWord
    %vt_DWord     = EnumType("DWORD")    As DWord
    %vt_Long      = EnumType("LONG")     As DWord
    %vt_Quad      = EnumType("QUAD")     As DWord
    %vt_Single    = EnumType("SINGLE")   As DWord
    %vt_Double    = EnumType("DOUBLE")   As DWord
    %vt_Ext       = EnumType("EXT")      As DWord
    %vt_Extended  = EnumType("EXTENDED") As DWord
    %vt_Currency  = EnumType("CURRENCY") As DWord
    %vt_String    = EnumType("String")   As DWord
    %vt_Heap      = EnumType("HEAP")     As DWord
     
    PrintL "types are enumerated now"
    PrintL
    PrintL HEAP_Get(%vt_Byte)
    PrintL HEAP_Get(%vt_Integer)
    PrintL HEAP_Get(%vt_Word)
    PrintL HEAP_Get(%vt_DWord)
    PrintL HEAP_Get(%vt_Long)
    PrintL HEAP_Get(%vt_Quad)
    PrintL HEAP_Get(%vt_Single)
    PrintL HEAP_Get(%vt_Double)
    PrintL HEAP_Get(%vt_Ext)
    PrintL HEAP_Get(%vt_Extended)
    PrintL HEAP_Get(%vt_Currency)
    PrintL HEAP_Get(%vt_String)
    PrintL HEAP_Get(%vt_Heap)    
    
    PrintL $CRLF & "key to continue"
    WaitKey
    
    PrintL "request integer :" & HEAP_Get(EnumType("integer",  TRUE)) 'should print integer
    PrintL "request currency:" & HEAP_Get(EnumType("CurrenCy", TRUE)) 'should print currency
    PrintL "request double  :" & HEAP_Get(EnumType("Double",   TRUE)) 'should print double
    PrintL "request quad    :" & HEAP_Get(EnumType("Quad",     TRUE)) 'should print quad
    PrintL "request String  :" & HEAP_Get(EnumType("String",   TRUE)) 'should print string
    
    
    PrintL $CRLF & "key to end"
    WaitKey 
    
    Function EnumType( ByVal sName     As String, _
              Optional ByVal testExist As Boolean = FALSE _
                     ) As DWord
      
      ' this funtion will store any passed string as is
      ' and return it's "unique number": 
      ' a pointer to heap containing the string 
      ' as passed for the very first time but
      ' this function is NOT case-sensitive!
      
      
      Static allNames(&H3FFF) As DWord
      Static numNames         As Long
      Static i As Long
      
      If StrPtrLen(StrPtr(sName)) < 1 Then Return 0
      
      i = Array Scan allNames Ptr, Collate Ucase, = Ucase$(sName)
      
      If i Then
        Return allNames(i)
      Else
        If testExist Then Return 0
      EndIf
      
      numNames += 1
      allNames(numNames) = HEAP_AllocByStr(sName)
      
      Function = allNames(numNames)
    End Function
    
    (the function was usually made to keep track of controls names - but for this example i used some other data i already had present)
    Last edited by ReneMiner; 14-09-2014 at 13:41.
    I think there are missing some Forum-sections as beta-testing and support

  5. #25
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,779
    Rep Power
    10
    Here it is the fix, I hope.

    As often happens: stupid error (in this case very stupid) difficult to find.

    Let m e know
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #26
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    cool everything runs fine- all 3 scripts testet ( the huge one and both of this thread )

    listen to my current favourite track while enjoying the success
    Attached Images Attached Images
    Last edited by ReneMiner; 14-09-2014 at 19:59.
    I think there are missing some Forum-sections as beta-testing and support

  7. #27
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    one question to that now, i assumed it would work but obviously not as i expected, assume toFind is some udt-variable consisting of a few dwords or longs and i want it only to compare 2 * 4 bytes starting at the 5th byte
    Long Index = Array Scan vPtr Ptr, Byte(5, 8), = toFind
    
    it does not seem to find the data matching this pattern - i have some small testscript attached, it's around line 138
    Attached Files Attached Files
    Last edited by ReneMiner; 05-10-2014 at 13:27.
    I think there are missing some Forum-sections as beta-testing and support

  8. #28
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    i isolated a little and found the following:

    Uses "console"
    
    Type some_Data
      pType As DWord  
      pName As DWord
      Index As Long
    End Type 
    
    Dim foo(5) As DWord
    Long i
    Dim dummy As some_Data At 0
    
    ' fill in some data
    For i = 1 To UBound(foo)
      foo(i) = HEAP_Alloc(SizeOf(dummy))
      SetAt( dummy, foo(i) )
      dummy.pType = i * 100
      dummy.pName = i * 200
      dummy.Index = i 
    Next
    
    Dim toFind As some_Data
    toFind.pName = 600
    toFind.Index = 3
    ' search for byte 5 to 12 only, should print 3:
    PrintL "1. found " & Str$( Array Scan foo Ptr, Byte(5, 8), = toFind )
    ' search for whole data, should print 0
    PrintL "2. found " & Str$( Array Scan foo Ptr, = toFind )
    
    ' now make the type match 
    toFind.pType = 300       
    
    ' search for byte 5 to 12 only, should print 3:
    PrintL "3. found " & Str$( Array Scan foo Ptr, Byte(5, 8), = toFind )
    ' search for whole data, should print 3
    PrintL "4. found " & Str$( Array Scan foo Ptr, = toFind )
    
    WaitKey
    
    if pType does not match even if meant to be ignored - it affects the scan-result.
    Last edited by ReneMiner; 05-10-2014 at 14:28.
    I think there are missing some Forum-sections as beta-testing and support

  9. #29
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    Seems the Byte-option gets ignored completely if the Ptr-option is used, test below proves that Byte-option works quite well on other data

    Uses "console"
    
    Type some_Data
      pType As DWord  
      pName As DWord
      Index As Long
    End Type 
    
    Dim foo(5) As some_data
    Long i
    
    ' fill in some data
    For i = 1 To UBound(foo)
      foo(i).pType = i * 100
      foo(i).pName = i * 200
      foo(i).Index = i 
    Next
    
    Dim toFind As some_Data
    
    toFind.pName = 600
    toFind.Index = 3
    ' search for byte 5 to 12 only, should print 3:
    PrintL "expect 3, found " & Str$( Array Scan foo, Byte(5, 8), = toFind )
    ' search for whole data, should print 0
    PrintL "expect 0, found " & Str$( Array Scan foo, = toFind )
    
    ' now make the type match 
    toFind.pType = 300       
    
    ' search for byte 5 to 12 only, should print 3:
    PrintL "expect 3, found " & Str$( Array Scan foo, Byte(5, 8), = toFind )
    ' search for whole data, should print 3
    PrintL "expect 3, found " & Str$( Array Scan foo, = toFind )
    
    
    WaitKey
    
    I think there are missing some Forum-sections as beta-testing and support

  10. #30
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,779
    Rep Power
    10
    Hi Rene,

    I will check later when back home.

    Ptr option is a very special option and is intended to be used only for arrays of pointers of something that is allocated using heap memory. Nothing more and nothing else. Very very specific case.
    In any case I will check you examples and see what I can do, add or fix.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 3 of 6 FirstFirst 12345 ... LastLast

Similar Threads

  1. OOP ideas
    By ErosOlmi in forum Suggestions/Ideas discussions
    Replies: 13
    Last Post: 26-08-2013, 20:26
  2. Ideas for dynamic Array-constructor on the fly
    By ReneMiner in forum Suggestions/Ideas discussions
    Replies: 0
    Last Post: 16-07-2013, 08:53
  3. copy array of UDT to another array in one step?
    By ReneMiner in forum thinBasic General
    Replies: 3
    Last Post: 02-11-2012, 01:15
  4. More Ideas
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 3
    Last Post: 27-10-2012, 14:47

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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