GetbufferSetLength(some_size)
和 GetBuffer(some_size)
之间到底有什么区别。
文档对我来说不是很清楚,对我来说,这两个函数听起来几乎都做或多或少相同的事情。
这是我的用例:
CStringA foo;
char *p = foo.GetBufferSetLength(somelength);
// fill the buffer p with exactly somelength (non null) chars
FillCharBufferWithStuff(p, somelength);
foo.ReleaseBuffer(somelength); // or should I rather use
// ReleaseBufferSetLength(somelength) ?
// now foo contains the somelength characters provided by FillCharBufferWithStuff
如果我使用
GetBuffer
而不是 GetBufferSetLength
,它的作用完全相同。
如果有人能阐明这一点,我将不胜感激。
如果您逐字发布函数参数,您会看到差异。
GetBufferSetLength(int nLength);
GetBuffer(int nMinBufferLength);
这种差异在描述中给出。
nMinBufferLength
nLength
CSimpleStringT
字符缓冲区的确切大小(以字符为单位)。
如果需要,GetBufferSetLength()
会截断或增加缓冲区长度,以完全匹配nLength
中指定的长度。
GetBuffer()
仅在必要时增加缓冲区长度以匹配 nMinBufferLength
中指定的最小长度。