Re: How to copy a CString to const char*
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Thu, 31 Mar 2005 13:15:44 -0500
That is indeed what is happening. Note that this is not the same as calling an API call
that makes a copy.
What I don't understand is the need to assign a literal to a CString!
CString s = _T("Something");
myPage2.m_psp.pszTitle = s;
This introduces a completely unnecessary intermediate copy!
The correct solution is
myPage2.m_psp.pszTitle = _T("Something");
at which point the pszTitle string points to a literal at a fixed location in memory! Then
there is no problem!
joe
On 29 Mar 2005 13:17:37 -0800, "Ajay Kalra" <ajaykalra@xxxxxxxxx> wrote:
>> Nothing is copied.
>
>I am guessing that is correct. It just points to a location in the
>memory. As the new CString object is allocated, this memory is freed
>and new allocation is elesewhere. This sounds unusual to me as you need
>to carry a string object with each of the titles to ensure it does not
>go out of scope.
>
>--------
>Ajay Kalra
>ajaykalra@xxxxxxxxx
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: How to copy a CString to const char*
- From: Ajay Kalra
- Re: How to copy a CString to const char*
- Prev by Date: Re: CAsyncSocket and performance issues
- Next by Date: Re: processor time allocation
- Previous by thread: Re: memory leak`s
- Next by thread: Re: How to copy a CString to const char*
- Index(es):
Relevant Pages
|