1

I have an app which gets content from internet. those pieces of information are so large and can't fit in memory.

LongListSelector does UI Virtualization well. remains Data Virtualization. I thought the solution is to save data in database first then show it.

I have no idea how to do it and these are questions in my head:

  • Is that how I should do Data Virtualization?
  • what happens if there is no enough space.
  • any source or tip is appreciated.

thanks.

user3293835
  • 829
  • 2
  • 15
  • 30

1 Answers1

1

Basic idea of data virtualization is creating custom collection that can load & return item(s) on-demand (without prior loading complete set in memory). Following is radically simplified implementation (adapted from this blog post) :

namespace VirtualizingDataTest
{
  public class VirtualizedDataSource : IList
  { 
    public object this[int index]
    {
      get
      {
        string text = "Requesting\t" + index;

        Debug.WriteLine(text);
        return "Item " + index;
      }
      set
      {
        throw new NotImplementedException();
      }
    }
}

In the sample above, new item created upon requested. In your case, if the online source provide a way to request item in specific index, you don't need database. You can put logic to download specific item in this[] getter. Further references (various better/more complete implementation) can be found here : https://stackoverflow.com/a/6712373/2998271

Given UI virtualization working, LLS will request only sub set of items to be displayed (in other words, this[] getter won't get invoked for all index available, only those to be displayed).

Community
  • 1
  • 1
har07
  • 88,338
  • 12
  • 84
  • 137
  • thanks @har07 .. So this way, we give new item to LLS without saving it in memory (`set` doesn't save anything) and after LLS finishes his work with item, that item goes away? I have not a good feeling with this. it needs to redownload items alway while scrolling – user3293835 Mar 05 '14 at 02:00
  • yes, this only demonstrates core idea, simplified as much as possible to address those who just begin to play with data virtualization. In the 1st link, author try to improve this using basic cache implementation to avoid redownloading too often. the 2nd link, as I said, provide various more complete implementation. – har07 Mar 05 '14 at 02:05