InitStorage for CListBox..!

  • Thread starter Thread starter jmarc
  • Start date Start date
J

jmarc

Doesn't seems to work!

Filling a CListBox with over 75,000 strings in it, took more than 5
minutes ! I tried using InitStorage( nbitems, length_item ) before filling
the
listbox, and it doesn't seem to change anything. Always very long before
having the list displayed. InitStorage is supposed to be used to allocate
CListBox memory before using AddStgring() and InsertString() functions...

Does anyone have succesfully used this InitStorage() function..???
(I'm not using Win 98.. with listbox limited to 32 thousands.. then)

Hoppefully, I had an alternate bussines strategy to offer to my client.
I simply displays 2,000 items along with a number indicating the right
items amount. But, it might be better to displays all of them in the
scrolling list.

I'll probably try to use AddString instead of InsertString,
when refreshing the whole list, and still keeping InsertString
and DeleteString when one item, or few of them, have to be
updated.

Or, anyone have any other ideas!

Thanks !
jmarc...
 
jmarc said:
Doesn't seems to work!

Filling a CListBox with over 75,000 strings in it, took more than 5
minutes ! I tried using InitStorage( nbitems, length_item ) before filling
the
listbox, and it doesn't seem to change anything. Always very long before
having the list displayed. InitStorage is supposed to be used to allocate
CListBox memory before using AddStgring() and InsertString() functions...

I'm going to completely ignore the question of whether is it good UI design
practice to have 75,000 items in a list box...

Is the CListBox automatically sorted? If it is, every call to AddString will
force a sort operation on the list each time a new string is added.
Seventy-five thousand sort operations on an ever-growing list is not trivial.
InsertString will avoid the sort operation, but you must supply an index
value of where in the list you want the new string to be placed (or -1 to
place the string at the end of the list).

The other thing to keep in mind is that CListBox::InitStorage merely avoids
the overhead of having to constantly reallocate memory for the list as more
items are added. It doesn't speed up the actual add/select/delete operations
for individual elements of the list.

Sean
 
Thanks for the answer! But it doesn't solve anything..!

Yes, the 'sorted' flag was true. So, I turn it off, and
rebuild my application, and try again. Not better..!

I use InsertString, always with the right index just over
the last item in the list.

My application take only 2,5 second to load thioses
75,000 items. And then take 3min 20 seconds to display!
It take almost no time, when I modify my application to display
only the first 50 items.

Like I said, the right bussiness strategy is to display around 2000
items. My customer fully agree with that. There is no Show Stopper
here, then. I post this question on the newsgroup, just hoping to learn
a little more about Windows widgets...

Thanks anyway!..
jmarc...
 
jmarc said:
My application take only 2,5 second to load thioses
75,000 items. And then take 3min 20 seconds to display!
It take almost no time, when I modify my application to display
only the first 50 items.

Every time you add a new item to a list box, you're sending a WM message
to it, and that's extremely inefficient. By deault, the list box owns
the strings, and it was designed to handle a few items only. If you need
to display 1000s of items, you need to program a virtual list box. That
means you don't feed the strings to the list box, all you do is tell the
number of items, and supply the strings on demand, always for the
currently visible items only.

To implement a virtual list box, use the flag LBS_NODATA instead of
LBS_HASSTRINGS (when you create the control). Send an LB_SETCOUNT
message to tell the control the number of items. Handle LB_GETTEXTLEN
and LB_GETTEXT to feed the strings from your own container to the list
box. You should not call AddString to add items to the list box. I don't
know the specific details regarding how to do this in MFC, but this is
the basic idea.

You'll be surprise how much faster it will work.

Tom
 
Thanks a lot, Tamas..

Your explanation is very helpfull.
It is important to know what wrong before
applying any solution.

I will be alble to find out how to proceed
in C++...

Thanks again..!
jmarc
 
Back
Top