Does a class have to allocate memory for its non-static member functions every time a new instance is created?
To put a finer point on it, if I were writing a class v3d representing 3-space vectors, would I use less memory by defining
static v3d::dotProduct(v3d v1, v3d v2)
as opposed to
v3d::dotProduct(v3d v2) ?
Neither static nor non-static member functions are stored per instance. In the case of non-static member functions, the way I understand it is that they are translated into something like (probably less readable than this):
And the calls to them are translated accordingly. If you want to improve performance, I would recommend using inline functions as these essentially copy the function contents to the place that you call it. I don’t think this will decrease your memory usage, but it’s worth using for class functions (static and non-static) which are called many times per second.
http://www.cplusplus.com/forum/articles/20600/