Only a simple question :
Which is best? Passing succefully the device in each (necessary) function call or simply create a new device in each class and call it when needed?
Ex.1 :
Passing device:
what you call in this case "create device for each class" is "storing the device pointer inside the class" (as you always use the same pointer in the whole class) !!!
well, storing the pointer would be a tiny little bit faster though...
and in this case I would use the storing methode...
passing a pointer to the function(s) would be neccessary if you use different pointers, e.g. if you have 2 or more scene managers you'd pass the pointer of the actualy needed scene manager to the function(s)...
but as long as you only have one device (in your example) the funtion(s) only can use this one and so there's no need to pass it to the function(s), so you can store the pointer...
But if use alot of classes, and I'm make tons of different Device pointers in each different class, wouldn't it be using a lot of memory. Its all a question of memory.
no, a pointer is just a long integer value...
it will cost more memory (temporaly) if you pass the pointer to each function, bc. the pointer will be copied on each call...
but even then it is always just a long integer and this is a realy minimal memory usage...
remember you pass/use a pointer not the whole instance !!!
a pointer just "points" to the memory where the instance is located !!!
the instance itself is only stored once in memory !!!
Last edited by Acki on Sat May 29, 2010 1:29 am, edited 4 times in total.