1

Topic: CString: GetBuffer vs GetBufferSetLength

Greetings to all,


Prompt, than differ GetBuffer (int) and GetBufferSetLength (int) at class ATL:: CAtlString?


Both returned buffers are assumed to be used for record in them any text data.

Naturally with the subsequent call ReleaseBuffer.


I will not understand, what difference between them?

2

Re: CString: GetBuffer vs GetBufferSetLength

Whether
such record is correct?





CAtlFile m_file; 
...
CString sFileContent; 
m_file. Read (sFileContent. GetBuffer ((int) nSize+1), (int) nSize); 
sFileContent. ReleaseBuffer (); 

3

Re: CString: GetBuffer vs GetBufferSetLength

Hello, Hayabusa, you wrote:

H> Greetings to all,

H> prompt, than differ GetBuffer (int) and GetBufferSetLength (int) at class ATL:: CAtlString?

H> Both returned buffers are assumed to be used for record in them any text data.
H> it is natural with the subsequent call ReleaseBuffer.

H> I will not understand, what difference between them?





    ATL:: CString str; 
    TCHAR * buff = str. GetBuffer (5); 
    int len = str. GetLength ();//0 
    str. ReleaseBuffer (); 

    buff = str. GetBufferSetLength (5); 
    int len2 = str. GetLength ();//5 
    str. ReleaseBuffer (); 

4

Re: CString: GetBuffer vs GetBufferSetLength

Hello, the Anonymous author, you wrote:

ATL:: CString str; 
TCHAR * buff = str. GetBuffer (5); 
int len = str. GetLength ();//0 
str. ReleaseBuffer (); 

buff = str. GetBufferSetLength (5); 
int len2 = str. GetLength ();//5 
str. ReleaseBuffer (); 
 



Also what it gives in real usage? , say, to a case in the message above.

to ReleaseBuffer msdn does not recommend to do other calls of class CString.

5

Re: CString: GetBuffer vs GetBufferSetLength

Hello, Hayabusa, you wrote:

H> prompt, than differ GetBuffer (int) and GetBufferSetLength (int) at class ATL:: CAtlString?
H> I will not understand, what difference between them?


Both return the pointer on the internal buffer, thus:

- GetBuffer () receives in parameter the minimum quantity of characters in  (and if needed it expands);

- GetBufferSetLength () receives in parameter an exact amount of characters in  and installs the size  in correspondence with it ( can be as it is expanded and cut off)

Both functions are often used to transfer internal  CString in   which as parameter accepts char*.

6

Re: CString: GetBuffer vs GetBufferSetLength

Hello, visual_wind, you wrote:

_> Both return the pointer on the internal buffer, thus:
_>  GetBuffer () receives in parameter the minimum quantity of characters in  (and if needed it expands);
_>  GetBufferSetLength () receives in parameter an exact amount of characters in  and installs the size  in correspondence with it ( can be as it is expanded and cut off)


Understood, 
smile

_> Both functions are often used to transfer internal  CString in   which as parameter accepts char*.


Well  it is clear, basically only and I use.