It might be useful to know what all parts of a computer do:
First of all, there's the processor, which executes the code. It is the heart of the computer. It fetches instructions and executes them. The speed of the processor usually determines the speed of your computer. To store data, it needs some external memory.
The external memory is called RAM. RAM is nothing more than storage, having more RAM rarely adds to the speed of a computer.
Now there's one gotcha here, the operating system. The operating system might support swapping (as most modern systems do), this means that if you run out of RAM, the operating system will write unused RAM to your (slow) hard drive and fetch it back when required.
Under normal circumstances this rarely ever happens. You usually have more than enough RAM to execute lots of processes at once. But in the rare case you try to execute a lot of processes requiring 1GB per process, you might trigger this. When this happens, your entire system slows down, not just one process. So
you don't seem to have problems with your RAM.
What might be happening in your case is that you are:
a: executing hundreds of processes at once, and the OS lets your program wait a while before giving it time to execute.
b: you hit "compile and run" in your IDE. This will cause a recompile of your program whenever you changed a source file. Compilation is a complicated process, and might take a while (2 seconds for simple projects, more for larger projects). This is
most likely the case.
But since we really want to rule out everything, try compiling and running this process:
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iostream>
#include <ctime>
int main()
{
std::clock_t oldtime = std::clock();
for(int i = 0; i < 100; ++i)
std::cout << "Iteration " << i << std::endl;
std::clock_t newtime = std::clock() - oldtime;
std::cout << "It took " << (((double)newtime) / CLOCKS_PER_SEC) << " seconds" << std::endl;
return 0;
}
|
This code measures the number of seconds it takes to actually
execute the process. If this value is high and varies wildly, then it might be a problem related to your OS not having time to execute your program, but otherwise, it's probably an error you make yourself.
Note that I put the important parts in bold, be sure to actually
read all the parts.