Conceptual and speed question

R

Roy Gourgi

Hi,



My program seems to slow down drastically because as I fill my array and
table with many values, the program suffers tremendously. The first thing my
program does is to search the jagged array to try to find an element in that
array. If it does not find that element in that array, then it adds another
element and that is the problem. Once I have many elements in that array, it
takes a long time to do a search. Furthermore, not only do I add an element
to that array if it does not find it, but I also add it to my table and as
my table gets bigger, it also slows everything down drastically.



What I thought may be possible is to create many arrays instead of only 1
array and that would speed up the search. The problem is that I do not know
what the size of each array will be at the beginning as some of the arrays
might be much larger than others. Is there a way to declare arrays and then
to dynamically increase their size when needed, and if it is possible would
this hamper the performance because my arrays will be quite large. I also
thought of maybe sorting the array, but that would take too long. Is there a
way to index an array to speed up the search?



As for my table in the database, I was wandering if I created many tables
would that also help speed up the process or will it not make a difference
because it is in the same database. And if that is the case that it does not
make a difference in speed because it is in the same database, then can I
save it to a different database? Another possibility I thought of is to save
the rows to another database and delete the rows in original database after
a certain number of rows have been added.







TIA

Roy
 
N

Nicholas Paldino [.NET/C# MVP]

Roy,

Why not use ArrayLists or List<T> for the dynamic arrays? They will
allocate the space for you as needed (doubling the current capacity every
time more memory is needed).

Also, have you considered a hashtable for your lookup? It would
probably be MUCH quicker than cycling through all of the elements of the
array. You would probably have to create a custom hash code provider and
comparer (.NET 2.0 has something for this, I'm not sure if .NET 1.1 has
something, or it might be in two separate interfaces).

Personally, I'd use the hashtable/dictionary approach.

Either that, or, you could create a tree out of your jagged array, and
search through that.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top