code optimization question

closed account (zwA4jE8b)
Using my game as an example again...

Is passing a variable such as HDC everytime a common function is called or creating a variable in the class and only initializing it once better?

I know in this simple game it will not make a performance difference, I just want to know for when I move to more complex projects.


The current version...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Snake Engine header
#ifndef H_snakengine
#define H_snakengine

class snake
{
	int _length, _counter, _tocount, i;
	RECT _old;
	std::vector<RECT> _segments;
	char _ret;
	
public:
	char _direction;
	snake(int);
	void snake_init();
	void snake_head(const HDC&);
	void snake_nextpos();
	void snake_animate(const HDC&);
	void snake_dead(const HDC&)
	void snake_addseg();
	char snake_collisions();
};
#endif 



or something like this...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//Snake Engine header
#ifndef H_snakengine
#define H_snakengine

class snake
{
	int _length, _counter, _tocount, i;
	RECT _old;
	std::vector<RECT> _segments;
	char _ret;
        HDC hDC;
	

public:
	char _direction;
	snake(int, const HDC);
	void snake_init();
	void snake_head();
	void snake_nextpos();
	void snake_animate();
	void snake_dead()
	void snake_addseg();
	char snake_collisions();
};
#endif 
closed account (zb0S216C)
It won't make a difference. Either way, you're referring to one HDC object in both examples.

Wazzak
closed account (zwA4jE8b)
oh ok. thank you. Ill just leave it as is then.
Topic archived. No new replies allowed.