About the MFC application: 
Author Message
 About the MFC application:

Hi,all:
 I build a program which is based on MFC and only call the
IActiveDesktop::SetWallpaper function each 5 seconds.Its release version
only has 140KB.But when run it,it engross about 2.5MB memory 20% cpu.Do you
know why? How I optimize it?


Sat, 26 Mar 2005 21:18:22 GMT  
 About the MFC application:

Quote:

> Hi,all:
>  I build a program which is based on MFC and only call the
> IActiveDesktop::SetWallpaper function each 5 seconds.Its release version
> only has 140KB.But when run it,it engross about 2.5MB memory 20% cpu.Do you
> know why? How I optimize it?

2.5MB of memory is nothing (it is virtual memory).  If you are measuring
this with the Windows Task Manager it is also a very inaccurate tool.
Nothing to worry about.

But consuming 20% of CPU is terrible!  Unless you are doing intense
continuous painting it probably means you have a polling loop somewhere
that should be redesigned.  Polling for anything is a big waste of CPU
time.

--
Scott McPhillips [VC++ MVP]



Sun, 27 Mar 2005 10:01:37 GMT  
 About the MFC application:


Quote:

>> Hi,all:
>>  I build a program which is based on MFC and only call the
>> IActiveDesktop::SetWallpaper function each 5 seconds.Its release
>> version only has 140KB.But when run it,it engross about 2.5MB memory
>> 20% cpu.Do you know why? How I optimize it?

> 2.5MB of memory is nothing (it is virtual memory).  If you are
> measuring this with the Windows Task Manager it is also a very
> inaccurate tool. Nothing to worry about.

> But consuming 20% of CPU is terrible!  Unless you are doing intense
> continuous painting it probably means you have a polling loop
> somewhere that should be redesigned.  Polling for anything is a big
> waste of CPU time.

> --
> Scott McPhillips [VC++ MVP]

Hi,Scott Mcphillips
 I only set the timer and call IActiveDesktop::SetWallpaper function each 5
seconds with it.What advise is bring forward for it?


Sun, 27 Mar 2005 12:30:56 GMT  
 About the MFC application:


Quote:

>> Hi,all:
>>  I build a program which is based on MFC and only call the
>> IActiveDesktop::SetWallpaper function each 5 seconds.Its release
>> version only has 140KB.But when run it,it engross about 2.5MB
memory
>> 20% cpu.Do you know why? How I optimize it?

> 2.5MB of memory is nothing (it is virtual memory).  If you are
> measuring this with the Windows Task Manager it is also a very
> inaccurate tool. Nothing to worry about.

> But consuming 20% of CPU is terrible!  Unless you are doing
intense
> continuous painting it probably means you have a polling loop
> somewhere that should be redesigned.  Polling for anything is a
big
> waste of CPU time.

> --
> Scott McPhillips [VC++ MVP]

Hi,Scott McPhillips
 If I use win API function instead of MFC,Do you think which can
the performance be proved?


Mon, 28 Mar 2005 17:07:43 GMT  
 About the MFC application:

Quote:

> Hi,Scott McPhillips
>  If I use win API function instead of MFC,Do you think which can
> the performance be proved?

No.  I think you have a design problem in your code.  Use the de{*filter*}
Break command and/or TRACE statements to find out what your code is
doing that consumes 20% of the CPU.  Analyze.

--
Scott McPhillips [VC++ MVP]



Mon, 28 Mar 2005 20:21:35 GMT  
 About the MFC application:


Quote:

>> Hi,Scott McPhillips
>>  If I use win API function instead of MFC,Do you think which can
>> the performance be proved?

> No.  I think you have a design problem in your code.  Use the de{*filter*}
> Break command and/or TRACE statements to find out what your code is
> doing that consumes 20% of the CPU.  Analyze.

> --
> Scott McPhillips [VC++ MVP]

Hi,Scott McPhillips
 Are you sure?I thiink it's ok.Now,I write the codes,please check it.
BOOL CSetWallpaperDlg::DynaDisplayOnDesktop()
{
        szBuf[0]=0;
        wsz[0]=0;
        static int iCount=-1;//for the loop
        int iItemCount=m_ListBox.GetCount();
        if(iItemCount<=1){
                AfxMessageBox("Add the file name,please.");
                return FALSE;
        }
        if(iCount>iItemCount-2)
                iCount=0;
        else
                iCount++;
        m_ListBox.GetText(iCount,szBuf);
        m_ListBox.SetSel(-1,FALSE);
        m_ListBox.SetSel(iCount,TRUE);
        MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,szBuf,-1,
                        wsz,MAX_PATH);
        hr=pActiveDesktop->SetWallpaper(wsz, 0 );
        if(FAILED(hr))
                return FALSE;
        hr=pActiveDesktop->ApplyChanges( AD_APPLY_ALL );
        if(FAILED(hr))
                return FALSE;
        else
                return TRUE;
Quote:
}

I set the timer 5 seconds.Then run above codes each 5 seconds.


Mon, 28 Mar 2005 20:56:43 GMT  
 About the MFC application:


Quote:

>> Hi,all:
>>  I build a program which is based on MFC and only call the
>> IActiveDesktop::SetWallpaper function each 5 seconds.Its release
>> version only has 140KB.But when run it,it engross about 2.5MB memory
>> 20% cpu.Do you know why? How I optimize it?

> 2.5MB of memory is nothing (it is virtual memory).  If you are
> measuring this with the Windows Task Manager it is also a very
> inaccurate tool. Nothing to worry about.

> But consuming 20% of CPU is terrible!  Unless you are doing intense
> continuous painting it probably means you have a polling loop
> somewhere that should be redesigned.  Polling for anything is a big
> waste of CPU time.

> --
> Scott McPhillips [VC++ MVP]

Hi,Scott McPhillips
 You think the Windows Task Manager is a very
 inaccurate tool.Could you offer an accurate tool?


Tue, 29 Mar 2005 09:16:00 GMT  
 About the MFC application:

Quote:

> Hi,Scott McPhillips
>  You think the Windows Task Manager is a very
>  inaccurate tool.Could you offer an accurate tool?

Hi Scott,

Perfmon.exe, found in the system directories.  One of its big
improvements over Task Manager is that its help system explains what the
various metrics mean.  Nobody knows what the Task Manager metrics
mean.   Select your process and select "private bytes" for a reasonable
measure of memory usage that your code is actually responsible for.

--
Scott McPhillips [VC++ MVP]



Tue, 29 Mar 2005 11:59:53 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Adding MFC-code to a non MFC Application(WIN-application)

2. Invoking/Controlling Java Application from MFC application

3. Converting MFC Application to Web Application

4. How to get the application startup path in an MFC application

5. mfc: custom animated skin for mfc-application

6. set_new_handler in non MFC library called from MFC application

7. MFC Custom animated skin for mfc-application

8. Adding MFC support to my non-MFC application

9. CAsyncSocket in an MFC DLL used in a non-MFC Application

10. Use of MFC Classes in ono=MFC Application

11. Loading a static-mfc-dll using ocx in a non-mfc application

12. Callback from MFC regular DLL to MFC application

 

 
Powered by phpBB® Forum Software