Click to See Complete Forum and Search --> : What is meant by optimization according to C and C++
sudhakarm
August 20th, 2005, 02:35 AM
Hi
My doubt is in the title itself,
"OPTIMIZATION according to C, C++"
what is meant by optimization and how we can achieve it thru C,C++....?
Thanks
Sudhakar.M
dude_1967
August 20th, 2005, 03:07 AM
Sudhakar,
In my opinion, the title is quite meaningful.
Please remember that there can be different meanings to the term optimization and optimization is always dependent on the intent of the optimization.
For example, you might place the emphasis of the optimization on the run-time performance or on the size of the executable code. These are usually conflicting goals since optimized run-time often results in code which can be a bit longer in the HEX-mask. Since size is rarely a problem on PC architectures, it can often be wise to emphasize performance. These trade-offs are typical for development in C. In fact, you must tune your C accordingly for your optimization emphasis.
Another interesting optimization can be achieved through use of high-level programming idioms and architectures in C++. The language, rich with object oriented features and the powerful STL, can be used to significantly shorten the optical length of code on the page. This can be a real relief for developers in the team but requires a high level of competence in the development group. Again the way you write the code will give it its look and feel---an optimization in C++.
A very rich topic. The ideas above will get you started.
Sincerely, Chris.
:thumb:
Hacker2
August 20th, 2005, 08:16 AM
optimization refers to improving the code in some way.
But which way?
1) Produce code in minimum time (hours spent coding)
2) Produce code with minimum bugs
3) Produce code with fastest execution speed
4) Produce code that is the easiest to read.
Generally, if you optimize one way, it is not optimized another way.
For example, fastest executing code is hard to read,
because you used programming tricks and arranged the code
in unusual ways to make it run fast.
But "optimize according to C and C++" does not explain much.
Can you provide more detail?
proghelper
August 20th, 2005, 02:34 PM
We wite programs to be executed using computers/machines.
Hence optimizing is all boout execution time I think. We can make a progam more readable but that does not mean that we optimize the program.
Also, you can instruct the compiler to take care of the optimizations to some extent. Various compilers provide compile time options to do that.
---------------------
Programming ( Assignment / Project ) Help (http://www.programminghelp4u.com/)
srikanth_mk
August 22nd, 2005, 08:06 AM
Code optimization refers to changes done to the code retaining the functionality, but increasing the eficiency of the program.
Now beauty lies in the eyes of the beholder, similarly efficiency lies in the eyes of the one who uses that code to achieve a goal.
However efficiency is usually associated with the RUNNING time of the program .So normally when u do code optimization u are trying to decrease the running time of the program (either through changing the logic but retaining the functionality or by using more efficeient program constructs).
int i, sum = 0;
for (i = 1; i <= N; i++)
sum += i;
printf ("sum: %d\n", sum);
can be rewriteen as:
int sum = (N * (N+1)) / 2;
printf ("sum: %d\n", sum);
Now after these, there are notations to indicate the efficiency of ur program i.e. big-oh, big-omega ...... ( and its little counter-paths)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.