Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2006

Tip: Looking for answers? Try searching our database.

InitStorage for CListBox..!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jmarc - 09 May 2006 21:33 GMT
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...
Sean M. DonCarlos - 09 May 2006 22:15 GMT
> Doesn't seems to work!
>
[quoted text clipped - 4 lines]
> 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
jmarc - 10 May 2006 18:23 GMT
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...

>> Doesn't seems to work!
>>
[quoted text clipped - 29 lines]
>
> Sean
Tamas Demjen - 10 May 2006 19:48 GMT
> 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
jmarc - 12 May 2006 17:19 GMT
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

>> My application take only 2,5 second to load thioses
>> 75,000 items.  And then take 3min 20 seconds to display!
[quoted text clipped - 20 lines]
>
> Tom

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.