1-million-row ListView

731 Views Asked by At

I have a SysListView32 that should potentially host millions of rows, and three columns of text A, B, C each < 256 characters.

Let's say column B has many many repetitions (example: column A is filename, column B is path, and each row is a file of the filesystem), and has only 100k different values (instead of several millions).

Is it possible to avoid duplication in RAM of content of column B of the ListView GUI element?

Can we fill a ListView with only pointers to arrays elements (taken from the 100k-element-array of different values of column B), instead of duplicated data?

How to modify this to make it work?

LV_ITEM item;
item.mask = LVIF_TEXT;
item.pszText = "Hello";
...
ListView_SetItem(hList, &item);
1

There are 1 best solutions below

4
On

What you need is also referred as "Virtual List". A virtual list control is a list view control that has the LVS_OWNERDATA style. This style enables the control to support an item count up to a DWORD (the default item count only extends to an int). However, the biggest advantage provided by this style is the ability to only have a subset of data items in memory at any one time. This allows the virtual list view control to lend itself for use with large databases of information, where specific methods of accessing data are already in place. For a given set of data (list or dynamic array), you need to follow these steps:

  1. Add LVS_OWNERDATA style to your ListView
  2. Make a call to CListCtrl::SetItemCount passing the data source size, like std::vector::size().
  3. Catch the LVN_GETDISPINFO notification. This is where the data is rendered into the ListCtrl.

Please have a look at the attached links I added, for more information and sample code. If you use CListView you can have access to the CListCtrl with GetListCtrl.

Links:

Virtual List Controls

Using virtual lists