Fastest way to lookup in tables
Fastest way to lookup in tables
Fastest way to lookup in tables
Fastest way to lookup in tables
Fastest way to lookup in tables
Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables
Fastest way to lookup in tables Fastest way to lookup in tables
Fastest way to lookup in tables
Go Back  Xtreme Visual Basic Talk > > > Fastest way to lookup in tables


Reply
 
Thread Tools Display Modes
  #1  
Old 02-19-2009, 07:09 AM
sesme sesme is offline
Newcomer
 
Join Date: Dec 2008
Posts: 8
Default Fastest way to lookup in tables


Hi. I have a program which will need to perform some lookup operations on a simple 2D table - i.e. match row and column values passed as strings and return the corresponding value within the table of data. The lookups will occur frequently and therefore the fastest, most efficient way is best. Where is best to put the table? Load it into an array at the program start, or store in a text file, or XML file, or use a mySQL table? Any help appreciated!
Reply With Quote
  #2  
Old 02-19-2009, 11:28 AM
torpkevuk's Avatar
torpkevuk torpkevuk is offline
Contributor
 
Join Date: Oct 2003
Location: Nebraska, USA
Posts: 640
Default

how much data will be stored in the table?
Reply With Quote
  #3  
Old 02-19-2009, 12:01 PM
frostic frostic is offline
Newcomer
 
Join Date: Feb 2009
Posts: 15
Default

It realy depends on the type of database you want to use i use mysql for doing databases. Using an xml or text you can populate the data into tables that you have created.

xml example
<rootnode>
<rownode>
<row1>texthere</row1>
<row2>texthere</row2>
<row3>texthere</row3>
<row4>texthere</row4>
<row5>texthere</row5>
</rownode>
<columnnode>
<column1>texthere</column1>
<column1>texthere</column1>
<column1>texthere</column1>
<column1>texthere</column1>
</columns>
</rootnode>
Reply With Quote
  #4  
Old 02-19-2009, 12:05 PM
frostic frostic is offline
Newcomer
 
Join Date: Feb 2009
Posts: 15
Default

then use a for each loop to pull the data into the columns and rows of your table this is just an example so any corrections would be appreciated.
Reply With Quote
  #5  
Old 02-19-2009, 12:13 PM
frostic frostic is offline
Newcomer
 
Join Date: Feb 2009
Posts: 15
Lightbulb

Code:
here is an idea how to write the data you want to the xml file
this is part of a game im making so it dont look like wat you want use it as a reference for writing to the xml file

Dim agentname As String = "C:/" & Login.txtNewAgent.Text & "_CIA" & ".xml"
        Dim NewAgentDoc As New System.Xml.XmlDocument
        Dim FullXML As String = "<root>"
        FullXML += "<Agent>"
        FullXML += "<Agentname>" & Login.txtNewAgent.Text
        FullXML += "</Agentname>"
        FullXML += "<AgentPass>" & Login.TxtNewAgentPass.Text
        FullXML += "</AgentPass>"
        FullXML += "<Agency>CIA"
        FullXML += "</Agency>"
        FullXML += "</Agent>"
        FullXML += "</root>"
        My.Computer.FileSystem.WriteAllText(agentname, FullXML, True)
Reply With Quote
  #6  
Old 02-19-2009, 02:02 PM
AtmaWeapon's Avatar
AtmaWeaponFastest way to lookup in tables AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

That's a lot of work, frostic. The .NET framework contains several different classes that ease the generation of XML documents, and the XML serialization framework could probably do what you're doing in 2 lines.

That aside, here's how the methods you listed stack up. Asking what the "best" is is very hard in software development, because the answer is dependent upon your context.
  • Arrays are very fast. However, arrays must be in memory. If you have a lot of data ("a lot" varies by machine) then you'll lose performance to the need to swap memory, you might not be able to load all of the data, or you could get complaints about your application's memory usage.
  • Files rely on slow file I/O. You might be able to structure the file in a way that you can grab the data you need relatively quickly, or you might be able to use random access to avoid loading too much of the file. Loading the entire file into memory is no different than using an array.
  • XML files must be parsed to be useful. This involves either using a SAX-like parser which has to start at the beginning of the document and work one way towards the data you need or a DOM parser that has to load the entire document into memory. The SAX parser is going to be slow unless you need to linearly read the contents of the file (in which case it's still slower than a standard text file) and the DOM parser has all the problems of arrays with less speed. Don't use XML for very large data sets.
  • A database was designed to store large amounts of data and return specific sets of data quickly. It's going to be slower than arrays, but not as slow as text or XML files. You won't have problems with memory usage, but you will require a database server which may be just as bad.
For a large dataset, I start by considering a database and only choose one of the other options if that's a no-go. If it's a lot of data, a binary file with a well-defined structure is probably your best bet. If it's a relatively small dataset, in-memory arrays might be acceptable.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #7  
Old 02-19-2009, 03:34 PM
sesme sesme is offline
Newcomer
 
Join Date: Dec 2008
Posts: 8
Default

thanks for the replies guys. As for table sizes, it's probably going to be about twenty tables with dimensions 30x30, mainly with 5 digit numbers stored in it. Would this be ok to load into an array?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Fastest way to lookup in tables
Fastest way to lookup in tables
Fastest way to lookup in tables Fastest way to lookup in tables
Fastest way to lookup in tables
Fastest way to lookup in tables
Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables Fastest way to lookup in tables
Fastest way to lookup in tables
Fastest way to lookup in tables
 
Fastest way to lookup in tables
Fastest way to lookup in tables
 
-->