We help IT Professionals succeed at work.

What are the best practices for my problem?

284 Views
Last Modified: 2010-08-05
Hi,

I am trying to resolve a little problem that would involve arrays in VB NET.

Let's assume I have the following array

                     Col1                        Col2                         Col3
Row1             "is"                           1                              10
Row2             "over"                      11                             20
Row3             "school"                   21                             30
...
...
RowN             "zen"                        2                              2

Col1--> is a string
Col2 --> is an integer
Col2 --> is an integer

From time to time I may need to INSERT a new line into that array but by keeping the data sorted according to Col1.... For instance, assuming I want to insert "japan" (Col1) , 11(Col2), 20 (Col3) after insertion the array would look like

                     Col1                        Col2                         Col3
Row1             "is"                           1                              10
Row2             "japan"                    11                            20
Row3             "over"                      21                             30
Row4             "school"                   31                             40
...
...
RowN             "zen"                        2                              2

I was wondering what would be the most *efficient* (meaning the most performance) way to do that using VB DOT NET arrays.    Posting some code would help.

Thank you for your help...
Comment
Watch Question

Praveen KumarArchitect

Commented:
I preffer DataTable instead of arrays it is case for me. Because it have lot of flexibility and perfomance issues.
if you need any code example using datatable, let me know
Racim BOUDJAKDJIDatabase Architect - Dba - Data Scientist
CERTIFIED EXPERT

Author

Commented:
<<if you need any code example using datatable, let me know>>
I have thought about using a datatable but there are specific reasons for which I want to use arrays.  Among these reason the question of performance (Directly working with arrays is much more faster thant working with DataTables).    Thank you for your assistance though.  I appreciate the intent.

Regards...
Praveen KumarArchitect

Commented:
If any database is interfaring in your application, defnetely consider using the DataTable.

Other choices are ArrayList and HashTable, both are good in perfomance.
Racim BOUDJAKDJIDatabase Architect - Dba - Data Scientist
CERTIFIED EXPERT

Author

Commented:
<<If any database is interfaring in your application, defnetely consider using the DataTable.>>
Yes I know, but it is not the case in this situation.  
Praveen KumarArchitect

Commented:
What about ArrayList and HashTable.
Just array will be more overhead, everytime when you ReDim'g the array (It will create a new array and copies the data)
Racim BOUDJAKDJIDatabase Architect - Dba - Data Scientist
CERTIFIED EXPERT

Author

Commented:
<<Just array will be more overhead, everytime when you ReDim'g the array (It will create a new array and copies the data)>>  
Sure, but to my knowledge arraylists are monodimensional whily I need a N X 3 array for the problem.   I do not want to have to  use several arrays.  Maybe multidimensional arrays are what I need.. Any ideas?
Praveen KumarArchitect

Commented:
Create a structure, then use a HashTable
you can add/remove/insert objects from HashTable easily.

By the way how many rows usually you have to store?
I am using a HashTable with 1000 objects , i did't find any perfomance issues.




Praveen KumarArchitect

Commented:
One more point is... Arrays (Multi/Single) can store only single datatype. You have strings and integers. If you create a string array, consider memory issues also.
Racim BOUDJAKDJIDatabase Architect - Dba - Data Scientist
CERTIFIED EXPERT

Author

Commented:
<<By the way how many rows usually you have to store?>>
Several billions...Does hashtable allow to store different data types? Does it allow sorting?  What's the difference between a hashtable and a datatable?

<<One more point is... Arrays (Multi/Single) can store only single datatype. >>
I see.. Can multidimensional arrays be sorted according to one criteria?
Architect
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Racim BOUDJAKDJIDatabase Architect - Dba - Data Scientist
CERTIFIED EXPERT

Author

Commented:
<<It is not a good idea to keep billions of records in the computer memory. You must consider using any database to store/retrive/sort...etc.>>
I know.  They are periodically loaded and unloaded from HD.

Thank you very much for your help...Your input has given me indication on what track I should follow.
Praveen KumarArchitect

Commented:
Glad to help you.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.