Advertisement

Avoid global variables?

Started by April 30, 2001 11:11 AM
13 comments, last by Moe 23 years, 9 months ago
An aside, the standardization of namespaces in C++ 1998 helps some to avoid global namespace pollution, however the question from the previous post still deserves a good answer.

-PlaneMith
quote:
Original post by Anonymous Poster

How do you pass values to WndProc without the use of globals? Whenever I use globals I put them in a global structure to avoid namespace conflicts.


One way would be to make use of the 32-bit value associated with each window for use by the application. This value is initially zero and can be changed with SetWindowLong() with GWL_USERDATA as the second parameter and can be accessed with GetWindowLong() with GWL_USERDATA as the second parameter.

You could create a structure local to WinMain() and just set that 32-bit value to the address of that structure. Then whenever you need to access that information just use GetWindowLong().

Anyway.. I hope that helps.

- Ian Perez (fett@willcomp.com) - "It is by will alone I set my mind in motion"

Edited by - [bobafet] on May 2, 2001 1:17:02 AM
- Ian Perez (iperez.fett@verizon.net) - "It is by will alone I set my mind in motion"
Advertisement
So avoiding globals is still a good idea?

Should I be bending over backward to avoid them even though my project is fairly small? (eg ~1600 lines)
quote:
Original post by Moe

So how do professional games handle things like this? Do they use the pointer method and keep track of all the meshes to be loaded in an array or something?


I (re)use a linked list template to store all of the objects that I load dynamicly. So, anything that isn''t needed isn''t in RAM, and when I want it there I tell it to load it. Having a static set of "containers" normally isn''t a good idea, and arrays are too slow to resize, so linked lists are a good idea.

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
Right now I don''t need to load in peticular meshes dynamically because I am just using 2 or so.

This topic is closed to new replies.

Advertisement