[En-Nut-Discussion] FRC: Direct or Pointer

Nathan Moore nategoose at gmail.com
Sun Nov 13 16:04:15 CET 2011


Switching from volatile to memory barriers should often produce smaller
code if the placement of the barriers is done smartly.  Access to a
volatile variable is almost treated like there are memory barriers before
and after each access -- even accesses that you might not realize are there
if the variable is used in a complicated C statement or if the volatile
variable is a pointer to data that is used a lot.

My referred way of dealing with this is to make local copies of the
variables I need at the start of the function and write the ones that may
have changes back out at the end of the function.  When this can be done it
lets the compiler optimise most of the code as access to local and
exclusively owned variables, but there are some cases where this can't be
done.

Nathan



More information about the En-Nut-Discussion mailing list