Click here to Skip to main content
14,768,261 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
I have developed a C# windows application in Visual Studio 12. When I run this application, it slows down all other apps and makes PC slow., I think it takes too much of physical memory. Pls suggest some work around to avoid slowing down my PC.
Below is the introduction to application developed :
The application is very data intensive. The application contains one for loop which loops through around 80000 times and this "for loop" also have one "inner for loop" which loops through 100000 time. I store all the data in lists, arrays and objects(I think these data structures consuming memory)
E.X. for(i=0;i<80000;i++)
{
for(j=0; j<10000;j++)
{
//do some scientific calculations using mathematical formulas (sine, cos, sqr roots) and calls some user defined functions
}
}

Also suggest how to make this application fast!!!
Posted
Comments
sja63 16-Oct-14 6:24am
   
Perhaps you can give us more detail about your processings in the doubled for loop.

I am a programmer since the early 90s, but I never had a problem to solve
in a 80000x100000 doubled loop. Of course this will slow down your system.

Maybe your design is wrong...

Or is your question simply a joke?
Nathan Minier 16-Oct-14 7:20am
   
No context on what you're doing, running "user defined functions" in nested loops, that have a control condition based strictly on an arbitrary number...

You have a fundamental design problem, or are running the sort of application that requires a dedicated machine. Figure out which it is and you'll maybe be able to get some advice on how to speed things up.

Edit: I should have added, my suspicion is that your design is flawed based on the nested looping tacked to static values.
BillWoodruff 16-Oct-14 7:52am
   
Without more information about how you are creating/initializing/writing-to your objects, arrays, lists, etc., inside the loops, I don't we can help you.
[no name] 16-Oct-14 21:16pm
   
I agree with others. It seems hard to believe that you are writing complex applications without understanding very basic principles. I mean "I've got a little 1200cc wagon and when I put 1 tonne of lead in the boot it seems to slow down. Why?"
I suggest you look at overall design, the specific algorithm and whether the PC resources are being properly utilised (all cores used for example). You may look at adapting algorithm to OpenMP or similar.

If a data intensive application is slowing down everything else, then it needs to utilise that CPU time to perform its processing. If you don't mind sharing the CPU time, however, pop a System.Threading.Thread.Sleep(0) call occasionally (particularly inside big loops). That will release the CPU to other processes and threads to be able to do their stuff, and the operating system will then award your program its fair share of the time-slices in turn.
   
The first thing to do is to verify if you really need to have nested loops doing the whole range each. If you can have an algorithm of O(m log n) instead of O(m) where m is the length of first loop and n the length of the second loop, then it would be much faster.

The second thing to verify is if you really need to have all in memory at once.

The third thing to do is to profile CPU usage. Visual Studio have required tools for that.

The final thing to check is memory usage. Again, you can use some memory profiling tools or you can have a rough idea using task manager.

If you memory usage is more than a few hundred of megabytes, then it might be possible that it has a significant impact on other application if your computer has very limited memory.

Finally for such big loops, you might have to consider caching issues and the choice of containers.
   
Hi there, seems you are running huge loops inside your code which is running on single thread. So either you use a multithreading application or use Application.DoEvents()

for(i=0;i<80000;i++)
{
	for(j=0; j<10000;j++)
	{ 
		//do some scientific calculations using mathematical formulas (sine, cos, sqr roots) and calls some user defined functions 
		Application.DoEvents();
	} 
	Application.DoEvents();
} 
   

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