Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any overhead using this-> for accessing a member?

When accessing a member of some class, I can use e.g.:

this->myVar = 10 

or I can just write:

myVar = 10

I like to use this-> because it explicitly declares that the variable is a member of this class, but does it cause any overhead in comparison to just using the variable name by itself?

As an alternative I could maybe add a unique prefix to the vars, such as _TmyVar, but I've been using this-> for a long time so I just wondered.

like image 734
Tom Avatar asked Nov 10 '10 23:11

Tom


People also ask

Do structs have overhead c++?

No. The size of all the types in the struct , and thus the offset to each member from the beginning of the struct , is known at compile-time, so the address used to fetch the values in the struct is every bit as knowable as the addresses of individual variables.

Does structure bring additional overhead to program justify?

Show activity on this post. No. Struct does not add any size, or have any overhead in the compiled C. It is a layer of syntax that requires additional work by the compiler, but has no overhead at runtime.


1 Answers

There is no overhead. The compiler will generate the exact same code for both versions.

like image 145
frast Avatar answered Oct 17 '22 08:10

frast