×

releasebuffer 代码

releasebuffer(下载文件的代码)

admin admin 发表于2023-09-09 00:36:45 浏览29 评论0

抢沙发发表评论

本文目录

下载文件的代码

用MFC的CInternetFile,CInternetSession,CHttpConnection等类,已知服务器名及文件路径,代码越简单越好。以下是代码片段://Download

releasebuffer函数是什么意思

GetBuffer和ReleaseBuffer是从其父类CSimpleStringT继承过来的。GetBuffer的作用是:“Returns a pointer to the internal character buffer”,ReleaseBuffer的作用是:“Releases control of the buffer allocated by GetBuffer.”。这两个函数的常见用法如下:CString str;const int bufferSize = 10;LPTSTR p = str.GetBuffer(bufferSize);_tcscpy_s(p, bufferSize, _T(“abcd1234.“)); // use the buffer directlystr.ReleaseBuffer(); // Surplus(多余的) memory released, p is now invalid.给GetBuffer函数传递的参数bufferSize,意思是:“The minimum size of the character buffer in characters. This value does not include space for a null terminator.”。对于调用ReleaseBuffer释放内存时,是否应该带参数,msdn是这样说的:“If you keep track of the string length yourself, you should not append the terminating null character. You must, however, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating null character, you should pass –1 (the default) for the length to ReleaseBuffer, and ReleaseBuffer will perform a strlen on the buffer to determine its length.”。因为ReleaseBuffer函数的默认参数是-1,所以通常在调用ReleaseBuffer函数时省去-1参数的书写。