Slow AddString Performance in MFC

I have a dialogue with several large combo boxes (maybe a few hundred pieces apiece). There is a noticeable delay in the construction, while they are populated (they confirmed that they are by profiling).

My initial thought was that sorting was killing its performance, but disabling sorting and using InsertString instead seemed not much better. I did not think this was like an excessive amount of objects - is there anything else I should do or consider here?

MFC calls are trivial wrappers for Win32 message calls, so I don’t think there is significant overhead there.

DUPLICATE How can I quickly load a large array of strings into an MFC list control?

+3
source share
1 answer

You should use CWnd :: SetRedraw around your additions to prevent the control from updating its entire internal state after each addition.

If you have not already done so, do the following:

combo.SetRedraw(FALSE);

...  All the adds

combo.SetRedraw(TRUE);
combo.Invalidate();

You should also consider using the CComboBox :: InitStorage function , which predefines the memory for the combo box.

+10
source

Source: https://habr.com/ru/post/1699340/


All Articles