Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  Suggestions to increase the performance of searching my array? (Monday, January 30, 2006)




Found the following interesting discussion in the Newsgroups:

Suggestions to increase the performance of searching my array?
by:Anonymous

I wonder if anyone has suggestions for reducing the amount of time it would take to search my array using the function that I have written. I want to find a position in the array of an item that matches on all three variables. Suggestions? Public Shared Function GetArrayPosition(ByVal ipRemoteEndPoint As String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer) For i As Integer = 0 To aryDevice.GetUpperBound(1) If aryDevice(0, i) = ipRemoteEndPoint.ToString And aryDevice(1, i) = intEngine_Type And aryDevice(2, i) = intEngine_ID Then Return i End If Next Return -1 End Function

 Reply:
by:Anonymous

 How can you create an array include different datatype (String, Integer). I suggest you use datatable.

 Reply:
by:Anonymous

 I was thinking about that after I posted and can change the format of the items so that they are all integers. Would this improve my situation or do you still recommend using a datatable? Dan

 Reply:
by:Cablewizard

 Dan, First, you don't want to mix types in an array. I noticed you have String and Integer types. If all 3 dimensions of your array reference a single item, then I might use an array of a Structure with a fixed length string. Second, do not perform multiple tests in a single line using the "And" operator. VB must resolve all the expressions prior to evaluating your comparison test. In cases where the first test fails, it will still perform the other two tests along with all the unnecessary overhead. VB.Net does include the "AndAlso" and "OrElse" operators which will provide a Meaning the first test to fail will cause the whole expression to fail, and return False without evaluating the subsequent expressions. IMHO, I prefer to break them into separate tests for readability. In addition, it also allows you to perform other operations between tests, as in the case of indexing. Third, along with the second, perform your tests in the order which will most likely give you a False first. This will allow you to minimize the number of unnecessary comparisons. Sometimes that fastest way to get to your desired item is to eliminate as many of the items as quickly as possible that cannot fulfill your criteria. Fourth, if you have a large number of elements in the array and you will be accessing them a lot, then I recommend pre-sorting the array on an appropriate key. You could also create Index arrays with pointers into the primary array and use this to minimize the number of elements to test. The best implementation of an Index, if even appropriate, would be dependant upon the contents of the array and intended usage. Hope this helps, Gerald take to search my array using the function that I have written. I want to find a position in the array of an item that matches on all three variables. Suggestions? ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer) = intEngine_Type And aryDevice(2, i) = intEngine_ID Then







 
Previous Posts
    - Where did my Dataset Go?
    - Password Filter DLL
    - An application framework for VB.NET
    - 'System.Net.WebException' - Strange Error
    - Dataset Tablenames <- SQLHelper
    - Add handlers to textboxes in a datagrid
    - Datagrid (windows forms)
    - Inheritance problem with custom control
    - Master details grid remove the cross
    - Unicode/international

Archives
    - 2006-01-01
    - 2006-01-08
    - 2006-01-15
    - 2006-01-22
    - 2006-01-29


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland