• Welcome to Valhalla Legends Archive.
 

instr for byte array

Started by o.OV, February 12, 2004, 01:17 AM

Previous topic - Next topic

Adron

Quote from: o.OV on February 14, 2004, 11:23 AM
Run-time error '49':
Bad DLL calling convention

mmm..


You're not supposed to use the Declare Lib's, because they don't work. Only use the tlb.

o.OV

Quote from: Adron on February 14, 2004, 11:32 AM
Quote from: o.OV on February 14, 2004, 11:23 AM
Run-time error '49':
Bad DLL calling convention

mmm..


You're not supposed to use the Declare Lib's, because they don't work. Only use the tlb.

Oh.. mm.. strange..
When I didn't have the declarations it crashed immediately. Weird.
If the facts don't fit the theory, change the facts. - Albert Einstein

Adron

Quote from: o.OV on February 14, 2004, 11:48 AM

Oh.. mm.. strange..
When I didn't have the declarations it crashed immediately. Weird.

I did mention that too... So, until someone explains what's wrong with the typelib, only run it in compiled form :P

o.OV

Quote from: Adron on February 14, 2004, 11:50 AM
Quote from: o.OV on February 14, 2004, 11:48 AM

Oh.. mm.. strange..
When I didn't have the declarations it crashed immediately. Weird.

I did mention that too... So, until someone explains what's wrong with the typelib, only run it in compiled form :P

Oh..  :o misunderstanding.
I thought you had it fixed.
If the facts don't fit the theory, change the facts. - Albert Einstein

o.OV

#19
*Sigh*
Adron..

With the code compiled, I found that the InByte sub I wrote was actually faster.. about twice as fast as instr.. and this changes alot of things ~_~

All this time I have been benchmarking test codes using a Start with "full" compile instead of a compiling an executable ..

I feel so stupid.. -closes eyes-

And I also tried to optimize your code the best I could.. sometimes it beat instr sometimes it didn't.
The non optimized version lost every time.

I'll see what else I can do with the API calls once I reboot.
_________________________________________

New test results.
API test is faster then the For Next.
I examined my coding and realized I had programmed it for strings with Padding for each entry.
With the API calls I could increase the the speed by about .35 times. Thanks Adron  ^^

I haven't written the version for padding yet..
but here is the regular one..
When processing 1000 or less bytes .. this api based function based on the example will be faster then InStr.



Function InByteNoPadding(a() As Byte, aStart As Long, aLen As Long, b() As Byte, bStart As Long, bLen As Long) As Long
   
   Dim ptr As Long
   ptr = memchr(a(aStart), b(bStart), aLen)
   If ptr Then
       Dim i As Long, base As Long
       Dim aStart_ As Long, aLen_ As Long, bStart_ As Long, bLen_ As Long
       aStart_ = 1 + aStart:   aLen_ = aLen + 1
       bStart_ = bStart + 1:   bLen_ = bLen - 1
       base = memchr(a(aStart), a(aStart), 1)
       Do
           i = ptr - base + aStart_
           If memcmp(a(i), b(bStart_), bLen_) = 0 Then InByteNoPadding = i - 1: Exit Function
           ptr = memchr(a(i), b(bStart), aLen_ - i)
       Loop While ptr
   End If
   
End Function

If the facts don't fit the theory, change the facts. - Albert Einstein

o.OV

Found it by accident
while looking for information on "_cdecl"

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q153586

It also shows a proper way to call it.
I'll test both improper and proper way
and see if I can find a speed difference.
If the facts don't fit the theory, change the facts. - Albert Einstein

Adron

Well, writing a wrapper in C is an obvious solution, but then you might as well write the whole thing in C.

o.OV

#22
With the original solution you had..
Would there be problems with the stack cleanup?

I'm guessing that is why you used a type library.

Add-On:
Is that why declaring it in a module would crash it?
If the facts don't fit the theory, change the facts. - Albert Einstein

Adron

Declaring using declare function crashes it because of calling convention. Using a type library, you can have it call it correctly. I don't understand why the type library causes an error.