当前位置:淘百问>百科问答>releasebuffer函数是什么意思

releasebuffer函数是什么意思

2023-11-17 01:58:32 编辑:join 浏览量:612

releasebuffer函数是什么意思

GetBuffer和ReleaseBuffer是从其父类CSimpleStringT继承过来的。GetBuffer的作用是:“Returnsapointertotheinternalcharacterbuffer”,ReleaseBuffer的作用是:“ReleasescontrolofthebufferallocatedbyGetBuffer.”。这两个函数的常见用法如下:CStringstr;constintbufferSize=10;LPTSTRp=str.GetBuffer(bufferSize);_tcscpy_s(p,bufferSize,_T("abcd1234."));//usethebufferdirectlystr.ReleaseBuffer();//Surplus(多余的)memoryreleased,pisnowinvalid.给GetBuffer函数传递的参数bufferSize,意思是:“Theminimumsizeofthecharacterbufferincharacters.Thisvaluedoesnotincludespaceforanullterminator.”。对于调用ReleaseBuffer释放内凯肢存时,是否应该带参数,局好msdn是这样说的:“Ifyoukeeptrackofthestringlengthyourself,youshouldnotappendtheterminatingnullcharacter.Youmust,however,specifythefinalstringlengthwhenyoureleasethebufferwithReleaseBuffer.Ifyoudoappendaterminatingnullcharacter,youshouldpass–1(thedefault)forthelengthtoReleaseBuffer,andReleaseBufferwillperformastrlenonthebuffertodetermineitslength.”盯腊世。因为ReleaseBuffer函数的默认参数是-1,所以通常在调用ReleaseBuffer函数时省去-1参数的书写。

标签:releasebuffer,函数

版权声明:文章由 淘百问 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.taobaiwen.com/answer/355787.html
热门文章