views:

106

answers:

5

i have a large list of static data from a server that i load on startup. I load this into a hashtable of foo objects. the user has a dropdown where they can choose one of these object. by default there are 50,000 objects which take up a lot of memory. i am trying to reduce memory

after monitoring usage, it turns out that most people only use about 1,000 of them. i want to have it so the gui only loads up those 1000 and if they need to select one that is outside that 1000 then they can go back to the server or to disk.

what would be the best way of doing this . .

+1  A: 

You have a dropdown with 50000 items in it? That seems a trifle excessive. Perhaps a list view control? Also you can create the listview as a Virtual list view - in this mode it will only load the items as needed, the other items can be loaded if they would be scrolled into view. Since you are having so many items in the list view, I suggest you work on some kind of search control that the user can use to narrow down the list of items.

1800 INFORMATION
A: 

Depending on the nature of your data how about forgetting about the whole thing and leave it up to the OS? Put it in a memory-mapped file.

Loren Pechtel
+3  A: 

I'm assuming you're filtering this list elsewhere...otherwise that's quite a list. The easiest way to hit your new, leaner static cache before hitting the DB will be to pass all requests through a single method:

public yourClass GetDesiredObject(string lkupValue)
{
  if (yourCachedHashtable.ContainsKey(lkupValue))
  {
     return yourCachedHashtable[lkupValue]
  }
  else
  {
     //Hit the db to retrieve the object values.
     yourClass obj = yourDatabaseCode.GetNewObject(lkupValue);
     //Add to the cache if desired.
     yourCachedHashtable.Add(lkupValue, obj);
     return obj;
  }
}
Peter J
+1  A: 

The problem with loading a 1000 first is

  1. Who would scroll a 1000?

  2. The going back to the disk will cause the dropdown to reset and they'll have to scroll again.

Solution

  1. Why not implement a auto search dropdown, and try caching app block, it works great for me with extensive amounts of data.

  2. Look at devexpress dropdown edit, you'll need to purchase their controls though.

Saif Khan
I agree with this solution, allowing them to do partial searching by typing the first few letters is definitely the optimal solution for a list so long.
Chris Marisic
+1  A: 

50,000 objects seems a bit excessive for a dropdown menu item. Maybe you want to look at an alternative widget, like a table with paging...

Stephane Grenier