Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Paging of child objects

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
ShailendraBaghel
Guest





PostPosted: Fri Dec 30, 2005 11:23 am    Post subject: Paging of child objects Reply with quote

I have a class which represents a Row and i have the following property to get Child objects

public Array Childs
{
get
{
return Array of child Row objects.
}
}

Row.ChildProperty="Childs"
Row.ChildPolicy=Infralution.Controls.VirtualTree.RowChildPolicy.LoadOnExpand;

In our application we can have a million child objects of a parent.
Now creating million child objects when user expands the row is not a good design as it is time consuming.
It might happen that user just sees the first 10 child objects and then scrolls down to view the last 10 child objects.

Is it possible that when user expands a row, memory of only first 100 child objects is allocated and when user scrolls down to view the next 100, then those child objects are allocated and so on?

Some psuedo-code will be helpful.

Thanks in advance.
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Dec 30, 2005 12:34 pm    Post subject: Reply with quote

The problem is that you are using an array as the collection to hold your child objects. This means that you will have to load the entire array upfront - requiring a large amount of memory and time to load.

What you need to do is to write your own collection class that implements the standard IList interface in a more intelligent way. The two main methods of this interface that you need to implement are:

1. Count – should return the total number of items in the collection.

2. Item(index) – should return the item at the given index.

Typically you might use a hashtable to act as cache to hold items you’ve already loaded (keyed by the collection index). So your Item method would first check the cache to see if you’ve loaded the item. If you haven’t then you would load the item at the given index from file/disk, store it in the cache and return it.

If you are getting data over a network (or other source where there is latency) you can improve performance by implementing a paging mechanism so that surrounding items are also loaded into the cache. This will reduce the number of round trips to get data.

If you implement a collection like this that handles loading data on demand then Virtual Tree will use the interface intelligently and only call the Item method (triggering load on demand) for those items it actually needs to display. This means for the example you gave that Virtual Tree will call the Count method to check how many children the parent has and then call the Item method for each item currently displayed.

The advantage of implementing the on demand loading in the collection rather than have Virtual Tree attempt some type of callback scheme is that the IList interface provides a ready to use interface that can nicely encapsulate this type of functionality and other parts of your application can then make use of the on demand loading mechanism.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group