Título: Instr para byte arrays [src] Publicado por: cobein en 31 Mayo 2009, 04:53 am Hace mucho que no posteo nada por aca.
Perdon por ponerlo en ingles pero no tengo ganas de escribir esto de vuelta. A friend of mine was doing some buffer parsing and he was needing a way to find certain bytes in a byte array (an Instr with bytes) so the first answer was, use two loops, one to increase the index in the buffer and the second to compare but, this was kinda crappy so after using the neurons for a while I came out with this solution. Its notably faster and it uses less iterations than a normal 2 loop seach , about [match position / match bytes len] match position is the index in the buffer where the first match is located. This function does not make use of any API, meaning it can be modded to speed it up but, I wanted to keep it simple to try the concept. http://www.mediafire.com/?sharekey=772aae6ba8d94e0c7432d3c9683f450ae04e75f6e8ebb871 Título: Re: Instr para byte arrays [src] Publicado por: XcryptOR en 31 Mayo 2009, 05:00 am very good, jajaja, i've already have seen on HH.
saludos Título: Re: Instr para byte arrays [src] Publicado por: LeandroA en 31 Mayo 2009, 05:51 am hola muy bueno, creo que se puede optimizar un poquito mas comparando el primer bits de la búsqueda con el del bucle general
Código: Public Function FindBytes2( _ ByRef bvSource() As Byte, _ ByRef bvMatch() As Byte) As Long Dim i As Long Dim j As Long Dim bFlag As Boolean Dim lChr As Long Dim LenMach As Long LenMach = UBound(bvMatch) FindBytes2 = -1 lChr = bvMatch(0) For i = 0 To UBound(bvSource) If lChr = bvSource(i) Then If LenMach > 0 Then For j = 1 To LenMach If i + j < UBound(bvSource) Then If bvMatch(j) = bvSource(i + j) Then bFlag = True Else bFlag = False Exit For End If End If Next If bFlag Then FindBytes2 = i Exit For End If Else FindBytes2 = i Exit Function End If End If Next End Function Saludos, y no te olvides de seguir compartiendos tus proyectos con los de habla hispana porque yo en HH esoy muerto jejej Título: Re: Instr para byte arrays [src] Publicado por: cobein en 31 Mayo 2009, 12:42 pm =D leandro fijate que hay 2 funciones, la que esta en el form es basica, es la de referencia, despues esta la otra que es mucho mas rapida (compilada) esta en un modulo, pero igual es verdad se puede optimizar la de referencia para ver las diferencia en velocidad.
|