473,382 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

InitStorage for CListBox..!

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...
May 10 '06 #1
4 1695
"jmarc" wrote:
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
May 10 '06 #2
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...
"Sean M. DonCarlos" <se********@newsgroups.nospam> wrote in message
news:80**********************************@microsof t.com...
"jmarc" wrote:
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

May 10 '06 #3
jmarc wrote:
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
May 10 '06 #4
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
"Tamas Demjen" <td*****@yahoo.com> wrote in message
news:u5**************@TK2MSFTNGP04.phx.gbl...
jmarc wrote:
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

May 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nicky | last post by:
hi,all For example, In MSDN help program, there are many items in the left list box when you type whatever key word. Can I get these itmes' text in anohter program? I did a test, put a CListBox...
1
by: Nicky | last post by:
hi,all For example, In MSDN help program, there are many items in the left list box when you type whatever key word. Can I get these itmes' text in anohter program? I did a test, put a CListBox...
1
by: Brent Baker | last post by:
Is there a way to change a CListBox from single selection to multiple selection, or back again, from inside the program after the CListBox has been created? Our application has several...
1
by: wayne | last post by:
hi, how can i read a list box from the first entry to the last? cos i understand that the cursor will be at the end and hence i wont b able to use GetCurSel(). thus how can i pick up the...
1
by: Pat Moline | last post by:
Today, we have an informational dialog where the information is displayed in a RichText control. The only action for the user is to press the OK button to dismiss the dialog. My desire is...
1
by: JMann101 | last post by:
I am writing a ASP.NET(VB) application and am having some trouble. I have a datagrid which list users and when an admin clicks "edit" a defined column becomes visible and a dynamic listbox control...
11
by: Özden Irmak | last post by:
Hello, In my VB.Net application I create a new instance of my form like : NewForm = new MyNewForm() But with this line, this new form is automatically shown. I want it to be hidden at the...
1
by: vermetpa | last post by:
Hello, My problem involves loading a listbox from a recordset. To start off this is the code in the initial update: void CEmployee4View::OnInitialUpdate() { m_pSet =...
0
by: Vincent RICHOMME | last post by:
Hi, I would need some help to write a templated function or method. I am developping a GUI and on one plateform I am using a listbox (CListBox) while on the other it's a combobox(CCombobox)....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.