Jump to content
  • Advertisement
Sign in to follow this  
dazscott

simple Q - rendering loop

This topic is 4830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it ok in c# to declare primitive variables and loop control variables inside a render loop, or does this eat memory? the code below for example, which just outputs some text to the screen. Is the new Rectangle(...) part going to create a new memory location each time the code is executed, or will it be done only once.
//to draw text inscreen co-ordinates
		private void Draw2DText(string text,Color c,float pos)
		{
			
			int x = this.Width/22;
			float y = (float) this.Height/pos;

			int yInt = (int) Math.Round(y,0);

			font.DrawText(textSprite, text, new Rectangle(x, yInt, 
			this.Width , this.Height ),
			DrawTextFormat.NoClip | DrawTextFormat.ExpandTabs |
			DrawTextFormat.WordBreak , c);
			
		}

Share this post


Link to post
Share on other sites
Advertisement
Quote:

the code below for example, which just outputs some text to the screen.
Is the new Rectangle(...) part going to create a new memory location each time the code is executed, or will it be done only once.

Yes, every time you use new, it will make a memory allocation. Of course, since you are using C# it will automagically be garbage collected.

Quote:
Original post by dazscott
Is it ok in c# to declare primitive variables and loop control variables inside a render loop, or does this eat memory?

Primitives will be allocated on the stack, so yes they do eat memory, but it is really negligable. Sometimes it's just necessary.

Share this post


Link to post
Share on other sites
yeah thats what I expected, The garbarge collector seems to be handling thinks ok for now at least.

thanks for the reply

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!