Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, i am writing a program in C++,and the program has a big function i call from a c++ file.i notice the ram usage has 20MB and it is spiking to 100MB then goes to 20MB.my question is it is bad for the computer or as a program to have a regular spiks ?or is it better to use global Variables so the program dont have to destroy the variable used inside the outside function?

What I have tried:

just try to understand if it is bad to the program performance i would like to hear your opinion
Posted
Updated 14-Dec-16 12:09pm
Comments
[no name] 14-Dec-16 14:56pm    
"is it is bad for the computer", I don't see how you would think that.
"program to have a regular spiks", yes it is perfectly normal for program to use and free up memory.
"program performance", don't worry about performance unless you can demonstrate an actual performance problem.
Member 12857672 14-Dec-16 14:59pm    
i dont have performance problem ,it something i saw and have no idea if it was good or bad.thank you
[no name] 14-Dec-16 20:31pm    
Just because you saw "something" somewhere doesn't mean you have a problem. You are worried about nothing.

Is it bad for the computer? No.

Is it base for performance? Possibly. It depends on if you like having 100MB of data swapped to disk and back into memory.

Debug the code and find where the spike is coming from.
 
Share this answer
 
Quote:
i notice the ram usage has 20MB and it is spiking to 100MB then goes to 20MB.my question is it is bad for the computer or as a program to have a regular spikes ?
No, not bad for the computer.
Without explanations of what is doing the program and how it is doing it, it is impossible to answer. the answer can be anywhere from worst design to the best design and perfectly normal to completely abnormal.

For example:
- A CDrom burner program will routinely an ISO of 800MB, it is normal.
- If you have a program that do a multiplication by using a recursive function which do a simple addition on every call would be a very bad design.

This code is doing a multiplication the worst possible way. it can call itself millions times and will take forever to complete.
C++
long long MyRecMult(long long a, long long b) {
    if (b!=0) {
        long long c= MyRecMult(a, b - 1);
    } else {
        return 0;
    }
    return a + c;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900