Here's what I did. I created an SDI app in VC++ 4.2. The view class is
derived from CListView. My system is a Pentium 200MHz, 64 MB RAM,
Windows NT 4.0 (Service Pack 2).
My app gives the user the ability to enable/disable the following options:
- Preallocate memory via SetItemCount()
- Use the LV_ITEM version of the InsertItem() function
- Disable redrawing via SetRedraw() [thanks for this idea Scott]
I added a menu item which lets the user decide how many records to add.
I set the list view up to have 4 columns (the main item column and three
subitems).
The app uses GetTickCount() at the beginning and end of the for()
loop to determine how much time has passed. It then divides this
interval by the number of items added to get a per item average.
The following benchmark results were obtained by adding 5000 records.
Preallocate Use the Disable Average
Memory LV_ITEM Redraw Time (ms)
=================================================================
F F F 2.000
T F F 1.638
F T F 2.010
T T F 1.638
F F T 1.378
T F T 1.107
F T T 1.442
T T T 1.101
It appears that using the LV_ITEM or not is irrelevant. This is not
surprising since the non LV_ITEM function just fills one with defaults
anyway.
However, disabling redraw and preallocating have now cut the average time
in half! Still, this is
a Pentium 200. Anyone want to run my app on another OS/Processor?
Have you tried turning off redrawing during the insertion/removal of large
numbers of items?
m_listctrl.SetRedraw( FALSE );
// Do insertions here
m_listctrl.SetRedraw( TRUE );
m_listctrl.Invalidate();
This will only affect your performance if the control is visible while you
are adding these items -- if you're doing it during OnInitDialog() or
something like that, you may not see any improvement...
---
Scott Smith
Peter Provost <ppro...@winfieldallen.com> wrote in article
<01bc0a48$48aea760$ac2bf7ce@hades>...
> Hello all,
>
> I've seen this question asked a few times before (thanks Deja News) but
> never really found a good answer.
>
> If I'm using a CListCtrl (or CListView) to display information being
> gathered from a database, and there may be many (>100) records, how do I
> speed up the insertion of items.
>
> I've written a little test app and discovered the following:
> - Using SetitemCount() to "pre-allocate" memory only improves
performance
> by about 10%
> - Using the version of InsertItem which takes an LV_ITEM is much slower
> than the one which takes text.
> - Adding subitems takes less than half the time as adding the item
>
> Now, I've downloaded the ActiveX SDK which documents the "new" common
> controls, one of which is a virtual list view. However, the docs make it
> very clear that this is a preview and is not to be used for production.
>
> So, finally, I ask, what is the best way to handle the adding of hundreds
> of items to a list view control?
>
> --
> ==========================================
> Peter Provost - Silver State Software Co.
> http://www.provost.org/peter
> mailto:pe...@provost.org
>
> JUNK EMAIL IS ILLEGAL. DON'T SEND ANY.
> ==========================================
>
>
if you want to drop the sample app into my mail account, I have a
couple of Alphas which are underworked. :-)
Cheers,
Felix.
----------
If you post a reply, kindly refrain from emailing it, too.
Preallocate Use the Disable Average
Memory LV_ITEM Redraw Time (ms)
=================================================================
F F F 1.12
T F F 1.18
F T F 1.10
T T F 1.19
F F T 0.558
T F T 0.641
F T T 0.556
T T T 0.643
Now... isn't this interesting! Pre-allocate actually slows it down in the
release build (even though it sped it up 10% in debug build!). It looks
like the biggest impact is made by calling SetRedraw(FALSE) over all the
others.
A few people are going to be running the test app on different machines for
me, so it should be interesting to compare the results.
try to disable the ListCtrl before you insert the items to it. This
improves the performance considerably because Windows does not need to
redraw the list every time a item is inserted.
m_ListCtrl.EnableWindow( FALSE );
for( .... )
// insert items
m_ListCtrl.EnableWindow( TRUE );
Markus
Joe O'
"Of course that's just my opinion, I could be wrong"
Peter Provost <ppro...@winfieldallen.com> wrote in article
<01bc0c97$a534d7b0$ac2bf7ce@hades>...
Anyone?
Joseph M. O'Leary <jmol...@earthlink.net> wrote in article
<01bc0cd9$2b5aaa90$7a552399@caffeine>...
I have no idea how callback items behave, if they essentially keep asking
you for display info it probably won't be very helpful. However, if the
behaviour is anything like the "Virtual ListView" ala New CommControls, one
might be able to get away with only caching a few items and selectively
loading them.