tweak said:
Thanks.
I read through the C-FAQ-list file again for malloc(). And I
think my question is very implementation specific as the only way
I know of to see how my compiler is treating my variables is to
look at the assembly, which is very platform (os and architecture)
specific and
doesn't help at all with porting code across platforms.
Nevertheless, even with computers being more powerful today, I do
not want to
write sloppy code. Back when I had my 80286 optimization was a
big
deal. Now, I guess porting is a bigger deal.
Hi Brian,
if you consider writing portable code, you should at least stick to
code which is conformal to standards like ANSI/ISO.
And I would propose that you avoid ANY optimization unless it is
unavoidable.
Not only, because it's often silly to do the machine's job, and the
built-in optimizers are doing it pretty good nowadays.
The other and to my opinion more important aspect is, that
optimization usually aims at an increased performance with respect
to speed or memory usage ...
If you move your code from one system/architecture to another,
there's a good chance that the priorities change.
One machine might have enormous memory resources, but might be
rather slow, while the other one is rocket-fast, but lacks of
memory. If you optimize your code for this one, it might fail on
the other one because of the optimizations.
You might end up with lots of machine/architecture dependent
#ifdef's and almost unreadable code.
There's another way:
take a sheet of paper (or some more...) and make a good design of
your project. Then check it under different aspects:
- speed
- memory expense
- peripheral requirements
Reduce it to the minimum wherever possible; leave out all
unnecessary features and gimmicks.
Then start implementing it.
You'll probably find out that you end up with a fast and tiny
program which meets all requirements
without code level optimization.
That's my experience...
(but I don't do it always, therefore I know).
Bernhard