例如,MSDN里面有这样一段代码:// The pointer to my list box.
extern CListBox* pmyListBox;// Dump all of the items in the list box.
#ifdef _DEBUG
CString str, str2;
int n;
for (int i=0;i < pmyListBox->GetCount();i++)
{
n = pmyListBox->GetTextLen( i );
pmyListBox->GetText( i, str.GetBuffer(n) );
str.ReleaseBuffer(); str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
afxDump << str2;
}
#endif
我的问题是,str.GetBuffer(n)这是返回的CString预先分配好的buffer吧? 这个buffer如何能保证自己接受一个很大的字符串? CString构造函数不可能分配一个无比巨大的字符串啊,它如何预知需要多少buffer?
而且,运行的过程中,str.GetBuffer(0)返回的内存地址,似乎并没有去realloc的地方啊。
extern CListBox* pmyListBox;// Dump all of the items in the list box.
#ifdef _DEBUG
CString str, str2;
int n;
for (int i=0;i < pmyListBox->GetCount();i++)
{
n = pmyListBox->GetTextLen( i );
pmyListBox->GetText( i, str.GetBuffer(n) );
str.ReleaseBuffer(); str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
afxDump << str2;
}
#endif
我的问题是,str.GetBuffer(n)这是返回的CString预先分配好的buffer吧? 这个buffer如何能保证自己接受一个很大的字符串? CString构造函数不可能分配一个无比巨大的字符串啊,它如何预知需要多少buffer?
而且,运行的过程中,str.GetBuffer(0)返回的内存地址,似乎并没有去realloc的地方啊。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货