|
-
October 15th, 2007, 10:02 PM
#1
Why the app will run slower when it occupied more memory?
When the app's memory usage is about 30M bytes, it runs fast.
But if it allocates a continuous big block of memory such as 100M bytes, while the cpu's load is constant and the physical memroy is enough. It will run much slower.
for example
Code:
//MyDoc.h
class MyDoc : public CDocument
{
//just allocate a big blcok of memory,but it won't be used
//as a result , the app will run much slower
double m_d[1024*1024*25];
}
What's the reason?
Thanks!
-
October 16th, 2007, 01:09 AM
#2
Re: Why the app will run slower when it occupied more memory?
When you say the app runs slowly what exactly do you mean? Slowly as in running the app in one shot is slow, OR slowly as in application is used over a period of time and it runs slowly during that time?
If you have enough physical memory AND if you are not using that big block of memory, then over time, one should not expect any performance degradation. I say over time because initially the process working set may be trimmed because of that big allocation, and some pages that would have been used might have been evicted, and then paged back in, but over time (like seconds) things should fall into equilibrium. Your big block of memory ** may ** be paged out and pages in use would stay in memory.
Say no to supplying ready made code for homework/work assignments!!
Please rate this post!
-
October 16th, 2007, 02:20 AM
#3
Re: Why the app will run slower when it occupied more memory?
 Originally Posted by UnderDog
When you say the app runs slowly what exactly do you mean? Slowly as in running the app in one shot is slow, OR slowly as in application is used over a period of time and it runs slowly during that time?
If you have enough physical memory AND if you are not using that big block of memory, then over time, one should not expect any performance degradation. I say over time because initially the process working set may be trimmed because of that big allocation, and some pages that would have been used might have been evicted, and then paged back in, but over time (like seconds) things should fall into equilibrium. Your big block of memory ** may ** be paged out and pages in use would stay in memory.
The app will run slowly during it's whole lifecycle.
But I found that if allocates memory by the way as below
Code:
method 1:
class CMyDocument:public CDocument
{
double * m_pD;
CMyDocument(){m_pD=new double[1024*1024*25];}
~CMyDocument(){delete[] m_pD;}
};
or
method 2:
class CMyDocument:public CDocument
{
static double m_D[1024*1024*25];
};
These won't slow down the app.
So I think that it's the way which MFC processing CDocument object cause the app runs slower.
Because neither method 1 nor method 2 make the CMyDocument object's size become enormous.But the way discussed in the topic article do.
-
October 16th, 2007, 02:28 AM
#4
Re: Why the app will run slower when it occupied more memory?
Are you making copies/multiple objects of MyDoc?
Say no to supplying ready made code for homework/work assignments!!
Please rate this post!
-
October 16th, 2007, 02:32 AM
#5
Re: Why the app will run slower when it occupied more memory?
 Originally Posted by UnderDog
Are you making copies/multiple objects of MyDoc?
No. The app was built as single document/view frame.
But even if I made copies objects of MyDoc. The memory will be allocated all the same.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|