Reputation: 5980
I have a combo box which I need to populate with potentially a large number of items, I have looked at the MSDN MFC documentation for CComboBox
and I have found the InitStorage
member function, with the following prototype:
int CComboBox::InitStorage( int nItems, UINT nBytes );
The parameters are listed as:
nItems: Specifies the number of items to add.
nBytes: Specifies the amount of memory, in bytes, to allocate for item strings.
This sounds like you specify the total amount of memory in the nBytes
parameter. However, the example they give conflicts with this:
// The pointer to my combo box.
extern CComboBox* pmyComboBox;
// Initialize the storage of the combo box to be 256 strings with
// about 10 characters per string, performance improvement.
int n = pmyComboBox->InitStorage(256, 10);
ASSERT(n != CB_ERRSPACE);
// Add 256 items to the combo box.
CString str;
for (int i=0;i < 256;i++)
{
str.Format(_T("item string %d"), i);
pmyComboBox->AddString( str );
}
This example suggests that the nBytes
parameter is actually the number of bytes to reserve per string, rather than in total. And this would make sense considering there is an nItems
parameter, so the total amount of memory could be easily calculated.
If anyone could clarify this I would be grateful.
Upvotes: 3
Views: 627
Reputation: 3874
This information by Raymond Chen would indicate that it is the TOTAL amount required for the strings not PER String.
http://blogs.msdn.com/b/oldnewthing/archive/2004/06/10/152612.aspx
This would make sense since it would give more control in situations where the string length is very variable.
Upvotes: 2