Fill a List with Large Amount of Data – Part 3

The previous article demonstrates how to improve performance by using a virtual listview control (having LVS_OWNERDATA style set) and handling LVN_GETDISPINFO notification. That’s pretty cool! However, it still can be improved by caching input data. That means, instead of first loading the whole input data, we can load only how much is necessary at a time.
For that purpose, before sending LVN_GETDISPINFO, a virtual list control sends LVN_ODCACHEHINT, giving a “hint” of what range of items should be loaded. An application can verify if these items are already loaded into cache. If not, then can load them.
Let’s see a simple example!

Using a cached list

  1. Set LVS_OWNERDATA style.
  2. Set the virtual list items count with CListCtrl::SetItemCountEx.
  3. Handle LVN_GETDISPINFO notification like in the previous example.
  4. Finally, handle LVN_ODCACHEHINT for loading cached data.

Notes

  • The caching mode presented here is as simple as posible. It presume the total number of items known. Also it adds data in cache each time is needed without care about memory. If necessary, that can be improved for handling an unspecified number of items and/or for keeping a maximum number of items in cache. That would be necessary if dealing with very large amounts of data.
  • See also the previous article notes.

Demo project

The demo project uses the same database and performs the same query like the one presented in the previous article. Please, feel free to download and compare.
Download: Cached_List_Demo.zip (Demo Project) (142)

Using Cached List - Demo Application

Using Cached List – Demo Application

Resources

See also

Leave a Reply