-
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
-
1 Attachment(s)
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
-
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
-
ok, i found something - seems array scan not always can find existing data when collate ucase, i made some example
Code:
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)
-
1 Attachment(s)
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
-
1 Attachment(s)
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
-
1 Attachment(s)
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
Code:
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
-
i isolated a little and found the following:
Code:
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.
-
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
Code:
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
-
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