Re: How to copy a CString to const char*

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
.



Relevant Pages

  • Re: Skirmish with .NET Framework versions 2.0, 3.0, 3.5 following update to SP1
    ... even though that allocated virtual memory may ... that allocation has to be made in ... Ken Blake, Microsoft MVP - Windows Desktop Experience ...
    (microsoft.public.windows.vista.general)
  • Re: Seven and pagefile
    ... memory and set it to 0? ... that allocation has to be made in ... Ken Blake, Microsoft MVP since 2003 ...
    (microsoft.public.windows.vista.general)
  • Re: Is MFC reusing memory?
    ... Regarding the indication the memory is not freed: ... in the debug version. ... What is a "non-MFC" allocation? ... You might read my essay on memory allocation on my MVP Tips site. ...
    (microsoft.public.vc.mfc)
  • Re: Cant set pagefile WinXP Home SP2
    ... Ken Blake, MVP wrote: ... No, it is never a good idea to disable the page file entirely, no matter how much memory you have. ... That's because Windows preallocates virtual memory in anticipation of a possible need for it, even though that allocated virtual memory may never be used. ... Without a page file, that allocation has to be made in real memory, thus tying up that memory and preventing it from being used for any purpose. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: How to release heap memory that is marked as free
    ... As I said, fragmentation is a very serious problem, and one of the most serious problems ... my allocator was accused of using massive amounts of memory. ... I'm going to have to re-think the memory allocation that I'm ... process's 'working set'. ...
    (microsoft.public.vc.mfc)