Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
03-03-2011, 03:09 PM #1
Do computers have more processing power than they have available RAM?
Am I wrong in thinking computers have more processing power than they have available RAM? When writing a program for computers, is it better to write the program assuming more memory, or more processing capabilities?
When programming there are certain tasks that need to be preformed that need the use of the processor. In many of these cases you can perform this task several times, or you can create a variable to store the information for use several times. You also have HDD limitations as well. Particularly in embedded systems.
That's my problem with these high level languages like C# and JAVA, I have no idea what's going on. They have a pre-built function for almost everything. I could import a library that has a hundred things I don't need to use one function that I could have written myself. How do you know exactly what is going on when you import a library? Where do you draw the line? How do you decide whether to import a library, or build the function yourself? How do you know when it would be better to create a new variable or keep doing the same process over and over?
I have also heard people talk about two functions that perform the same task, but one is better than the other in someway or another. How do you find these things out?
I always try to write my programs with as few variables as possible. Sometimes when I'm in school I get the chance to see other students work. I found that for every ten variables in their assignment, I have one, sometimes less.
I used to work with this guy who when programming PLCs, his goal was to do it in as few rungs as possible. I swear, he would make the program two times more complicated just to eliminate one rung, and I'm talking about fairly simple and short programs too. That's not how he saw it of course...
How do you write your programs, with respect to the above? Obviously, most of use strive for a happy medium somewhere, but which do you tend to lean to? Do you write them to be more memory efficient, more processor efficient, more space efficient, or something else like more code readable?--www.firemelt.net--
* No good deed goes unpunished.
* Cheer up, the worst has yet to come...
03-03-2011, 08:06 PM #2
- Join Date
- Jun 2002
- Thanked 328 Times in 324 Posts
It is a complicated question and can depend on a lot of factors. Generally speaking you should always make your code make efficient use of all the resources (CPU, Memory, Disk) as much as possible.
Now how far you take that in terms of how you write your code can vary. It is a cost versus benefit thing, if you make your program use .1% less memory at the expense of harder to maintain code, it might not be worth it. Or if you spend 10 hours and make a program 5% faster, it may or may not be worth it. There isn't a single guideline you can work off of, it is mostly a judgment call that is formed from experience. And it depends on the type of program you are working on. For example if you are working on some sort of program that is analyzing data and takes 10 hours a day to complete, spending 10 hours working on the code to make it go 5% faster could be useful. Some times sacrificing a little CPU time and/or memory is necessary if it makes the API a lot easier to use.
When writing software for an embedded device, your resources are more constrained but it isn't as bad as it might seem. For example on a microcontroller it is common to only have 1.5-3KB of RAM. It might not seem like a lot but since your code is running directly on the hardware, you can go quite a ways on 1.5KB of RAM. In addition embedded systems like that tend to have processors with a lot more CPU registers than on other architectures like x86. For example AVR microcontrollers have 32 general purpose CPU registers if I remember right. So in a function most of the local variables will use the CPU registers instead of stack space.
In regards to your questions about C# and Java and import libraries, yes those are going to be less efficient than a C program. But the benefit is shorter development times and increased portability. And with import libraries, yes there is going to be loaded code that your program might not use but that is why for example the .NET framework is broken up into lots of different assemblies, so the overhead isn't as big.OracleGuy