Sign in to follow this  
Thirthe

should i use method parameters or class members?

Recommended Posts

Thirthe    128
Hello, gamedev! So, I have this class...
class Object
{
	public:

		void setObject( const float w, const float h );

        private:
                float width, height;

};

void Object::setObject( const float w, const float h )
{
        width = w;
        height = h;

        // from now on, what should i use? w/h or width/height?
        // is one or the other accessed faster?
}

thank you.

Share this post


Link to post
Share on other sites
DevFred    840
The parameters might be faster, because they are allocated on the stack. The instance variables must be accessed indirectly via the this pointer, although depending on the computer architecture, it may not matter at all.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this