Paul D. Buck wrote:
> On Apr 22, 2009, at 4:01 AM, Paul D. Buck wrote:
// Set next_scheduler_state to preempt
//
for (i=0; i< active_tasks.active_tasks.size(); i++) {
> You might have been happier if I never looked at the code ...
Such is the power of Open Source and Peer Review!
One minor detail, *pre-increment vs post-increment* :
For the sake of C & C++ code size and code efficiency, a good rule of
thumb is to use primarily /pre-increment/ (eg: "++i") and to only use
post-increment when it specifically makes good sense to do so.
That makes a BIG difference on certain old compilers. It still makes a
(small) difference even on today's optimising compilers.
A good explanation is given on:
Loop- Post increment, pre increment count
http://www.codeguru.com/forum/archive/index.php/t-384898.html
####
...pre-incrementation does reduce CPU cycles because it uses one
less instruction than post incrementation, but this will make little to
no difference in most programs that you write. At least while in the
learning phase
One less instruction?
Not for builtin types.
For builtin types, there is no difference, as long as the yielded value
is not used (at least for all common compiler, including Turbo C++ 1.0).
And, if the yielded value is used, such as in:
*p++ vs *++p, then the post-increment is likely to be a bit faster (not
significantly) on modern CPU.
Because, instead of:
; pre-increment with space optimization
inc esi
mov eax,[esi] ; AGI stall (on pentium CPU) + dependency
; pre-increment with speed optimization
mov eax,[esi+1] ; four bytes of code are lost, but 1 or 2 CPU cycles gained.
inc esi
; post-increment with speed or space optimization
mov eax,[esi]
inc esi
Of course, that is more subtle than that, if other operations are
combined, but *p++ is easier to optimize than *++p.
However, for iterators, ++p is very often MUCH faster than p++.
So, the rule is : Use ++p as often as you can, and p++ only if you need
it (that is, almost never).
####
Longer comments are given in:
Writing optimizer-friendly code
http://www.iar.com/website1/1.0.1.0/481/1/
Hope of interest,
Regards,
Martin
--
--------------------
Martin Lomas
m_boincdev ml1 co uk.ddSPAM.dd
--------------------
_______________________________________________
boinc_dev mailing list
[email protected]
http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev
To unsubscribe, visit the above URL and
(near bottom of page) enter your email address.