I'm new to C++ and am attempting to figure out what I'm supposed to do.
Is there a difference in performance between the following options:
const DATATYPE* name vs
DATATYPE* name In this case there shouldn't actually be any performance gain, because the keyword const in your example only tells the compiler that the pointer access will be limited to read-only access (this could only increase performance e.g. in cases with mutex-protected or atomic pointers). But the pointer itself is going to be a variable!
If, however, you meant to use a constant pointer to a read-only value, then you would have had to declare it like this:
const DATATYPE *const name
And even in this revised case, most compilers shouldn't see any performance improvements, because good compilers automatically detect if something is actually treated as a constant and/or read-only entity in a given code and then optimize accordingly (internally) without the programmer having to bother with redundant and excessive "const embellishments" everywhere. (Not saying all const uses are redunant -- far from it, as e.g. const explicitly used to define a read-only entity makes for a good and safe API.)
const is more important than just for readability. For instance, only a const reference can bind to a temporary.
constvariables. But that's the least important function ofconst(and it's unlikely you will notice any difference in performance anyway).const. And if you can then please try to avoid pointers at all.DATATYPE* const)objdumpto see if the compiler has done any optimizations for one over the other. In general though, don't concern yourself with the optimization, useconst T *whenever you don't have to modify the dereferenced value, otherwise don't useconst.name->method()ends up calling a different function because of the const.