Hi all,
In the beginner tut # 4 it becomes obvious that the ComposeFrame() gets called constantly upon each frame.
Is it a good idea to be constantly declaring x with 'int x;' ?
What is happening inside the computer when this happens? Does it ignore it because it's already declared, or does it create a brand new slot in memory for another x (and if so what does it do to the previous slot)?
Thanks,
Tom.
What is happening to 'int x;' when refresh code?
What is happening to 'int x;' when refresh code?
Last edited by Tommy on December 1st, 2012, 9:17 am, edited 1 time in total.
Re: What is happening to 'int x;' when refresh code?
Just keep watching and you will see that you are right, you shouldn't be updating those every frame. Only when they change is when values should be changed. You will also find out that they shouldn't be in the Compose Frame function anyways and should be initialized with a constructor type initialized list.
MOOOOOO
Re: What is happening to 'int x;' when refresh code?
Sorry, I got my terminology wrong. I think I meant 'declare' not 'initialize'.
EDITL I kept watching, seems like the variables are destroyed at the end of the function.
(someone can confirm?)
EDITL I kept watching, seems like the variables are destroyed at the end of the function.
(someone can confirm?)
Re: What is happening to 'int x;' when refresh code?
Yeah, as soon as you exit the scope where you declared the value, in this case compose frame, the "x" will be erased from memory.
Later when you get to allocated memory you will need to watch out what you declare and free the memory manually or you will have memory leaks.
Later when you get to allocated memory you will need to watch out what you declare and free the memory manually or you will have memory leaks.
ʕ •ᴥ•ʔ
Re: What is happening to 'int x;' when refresh code?
Thanks guys.
These tutorials really are great. Compared to all the other tuts I've watched, these really are much simpler. Maybe it's thanks to the simple framework. I hope Chili continues onto Advanced tuts after the intermediate.
These tutorials really are great. Compared to all the other tuts I've watched, these really are much simpler. Maybe it's thanks to the simple framework. I hope Chili continues onto Advanced tuts after the intermediate.