Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Optimizing Arrays

I've made a VB .Net application that use arrays, a lot. I'm optimizing my application for speed because it is very slow, specially in the areas where arrays are massively used.
I've searched in google and books and i found technics to speed up array search but none of them referenced multi-dimensional arrays, so the question i've been making for months remains:
How can i speed up multi-dimensional array search?
As an example i have the function listed bellow that is inserted in one of the code areas where the windows task manager blows of scale and the cpu usage reaches 100% and my application hangs for while (enough time for the picturebox to present a red cross instead of the image)
Can You help?


Public Function returnPoint(ByVal x As Integer, ByVal y As Integer) As String
Dim strReturn As String = ""
Dim intCounter As Integer

For intCounter = 0 To UBound(ArrayPontos) - 1

If (ArrayPontos(intCounter).lngValueY = y) AndAlso (ArrayPontos(intCounter).lngValueX = x) Then
strReturn = ArrayPontos(intCounter).strPointName
End If
Next

Return strReturn
End Function

My thanks in Advanced

Ricardo Furtado

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : I've made a VB .Net application that use arrays, a lot. I'm
    : optimizing my application for speed because it is very slow,
    : specially in the areas where arrays are massively used.
    : I've searched in google and books and i found technics to speed up
    : array search but none of them referenced multi-dimensional arrays,
    : so the question i've been making for months remains:
    : How can i speed up multi-dimensional array search?
    : As an example i have the function listed bellow that is inserted in
    : one of the code areas where the windows task manager blows of scale
    : and the cpu usage reaches 100% and my application hangs for while
    : (enough time for the picturebox to present a red cross instead of
    : the image)
    : Can You help?
    :
    :
    : Public Function returnPoint(ByVal x As Integer, ByVal y As Integer)
    : As String
    : Dim strReturn As String = ""
    : Dim intCounter As Integer
    :
    : For intCounter = 0 To UBound(ArrayPontos) - 1
    :
    : If (ArrayPontos(intCounter).lngValueY = y) AndAlso
    : (ArrayPontos(intCounter).lngValueX = x) Then
    : strReturn = ArrayPontos(intCounter).strPointName
    [color=Blue]Exit For[/color]
    : End If
    : Next
    :
    : Return strReturn
    : End Function
    :
    : My thanks in Advanced
    :
    : Ricardo Furtado

    See the addition in blue. Might save you some speed. Other than that, there is no quicker way of searching this array (which is 1 dimensional btw). Atleast, not without doing some pre-sorting.
    And it's worth to note that .NET produces relatively slow code. A program that would be done within a second when programmed with VB6 would take much longer to run in VB.NET. And even then, if you programmed it in C it would be even faster.

    EDIT: Also, how are you using the returned string? Wouldn't it be wiser to return the index of the element?
    And if I may ask: is there a reason to make it a 1D array, rather than a 2D (x,y) array?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.