What is happening to 'int x;' when refresh code?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Tommy
Posts: 11
Joined: December 1st, 2012, 7:14 am

What is happening to 'int x;' when refresh code?

Post by Tommy » December 1st, 2012, 7:17 am

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.
Last edited by Tommy on December 1st, 2012, 9:17 am, edited 1 time in total.

User avatar
codinitup
Posts: 112
Joined: June 27th, 2012, 7:43 am

Re: What is happening to 'int x;' when refresh code?

Post by codinitup » December 1st, 2012, 7:57 am

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

Tommy
Posts: 11
Joined: December 1st, 2012, 7:14 am

Re: What is happening to 'int x;' when refresh code?

Post by Tommy » December 1st, 2012, 9:17 am

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?)

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: What is happening to 'int x;' when refresh code?

Post by LuX » December 1st, 2012, 10:22 am

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.
ʕ •ᴥ•ʔ

Tommy
Posts: 11
Joined: December 1st, 2012, 7:14 am

Re: What is happening to 'int x;' when refresh code?

Post by Tommy » December 1st, 2012, 11:08 am

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.

Post Reply