FraserOfSmeg
FraserOfSmeg

Reputation: 1148

How to speed up this code

I've been working on a memory editor for a while now. One of the key aspects of it is look through the memory for values that match a search term. This is however extremely slow. Here's the code:

For i = 0 To 1318706384 - 4 Step 4

    For j = 0 To 3
        temparry(j) = alldata(i + j)
    Next

    tempint = BitConverter.ToSingle(temparry, 0)

    If tempint + 0.01 > xposs AndAlso tempint - 0.01 < xposs Then
        ReDim Preserve xpos(xpos.GetLength(0))
        xpos(xpos.GetLength(0) - 1) = i

    End If

    If InStrRev(i.ToString, "000000") > 0 Then
        Label1.Text = i / 1318706384 * 100
        Me.Update()
    End If
Next

Any advice on how to speed it up would be great! The xpos array is only redim'ed about 50 times so that does't make up a large amount of the time (it's a small array). Thanks!

Upvotes: 0

Views: 108

Answers (1)

tinstaafl
tinstaafl

Reputation: 6948

One thing that should help with the speed is, instead of creating a temporary array just pass the start index to BitConverter.ToSingle.

'For j = 0 To 3
    'temparry(j) = alldata(i + j)
'Next

tempint = BitConverter.ToSingle(alldata, i)

if the 0's your searching for in that last bit are at the end then the modulus operator, Mod, should probably work better than casting i to a string and searching the string

If i Mod Math.Pow(10,5) = 0 Then

Upvotes: 1

Related Questions