<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.xna.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>General</title><link>http://forums.xna.com/forums/50.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 0.0)</generator><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191545.aspx</link><pubDate>Fri, 19 Jun 2009 17:26:54 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191545</guid><dc:creator>jmartingarcia</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191545.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191545</wfw:commentRss><description>Yes, is only for positive values in this case. &lt;br /&gt;
&lt;br /&gt;
Thanks &lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191544.aspx</link><pubDate>Fri, 19 Jun 2009 17:22:49 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191544</guid><dc:creator>jmartingarcia</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191544.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191544</wfw:commentRss><description>Brilliant !!&lt;br /&gt;
&lt;br /&gt;
Thanks !&lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191543.aspx</link><pubDate>Fri, 19 Jun 2009 17:20:19 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191543</guid><dc:creator>The ZMan</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191543.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191543</wfw:commentRss><description>&lt;a href="http://msdn.microsoft.com/en-us/library/system.math.round.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.math.round.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Adding .5 works properly for +ve values only (most of the time for drawing sprites unless you have some transforms involved)&lt;br /&gt;
&lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191541.aspx</link><pubDate>Fri, 19 Jun 2009 17:13:15 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191541</guid><dc:creator>Nick Gravelyn</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191541.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191541</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="http://forums.xna.com//Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;jmartingarcia:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;2.- That won&amp;#39;t really work I think. You see, if the X position is the pixel 1.90 then should be the pixel 2 and not the pixel 1 on the screen.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; When I convert from world units to pixels I will get fractional pixels that I need to convert to the best matching pixel position.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;There&amp;#39;s actually a little trick you can do with this. Basically add .5 to the number and cast to integer. Then if the number was .5 or more towards the next number, it will round correctly. So make a custom round method:&lt;br /&gt;
&lt;br /&gt;
&lt;div style="border:1px solid #7f9db9;overflow:auto;background-color:white;font-family:courier new;font-size:11px;"&gt;
&lt;table cellspacing="0" cellpadding="0" style="border-width:0px;border-bottom:0px solid #eeeeee;margin:2px 0px;width:99%;border-collapse:collapse;background-color:#ffffff;"&gt;
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;span style="font-size:11px;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;static&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;MyRound(&lt;/span&gt;&lt;span style="color:blue;"&gt;float&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;input)&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;{&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:blue;"&gt;return&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:11px;"&gt;)(input&amp;nbsp;+&amp;nbsp;.5f);&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;}&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
Then give it a try with some numbers:&lt;br /&gt;
&lt;br /&gt;
&lt;div style="border:1px solid #7f9db9;overflow:auto;background-color:white;font-family:courier new;font-size:11px;"&gt;
&lt;table cellspacing="0" cellpadding="0" style="border-width:0px;border-bottom:0px solid #eeeeee;margin:2px 0px;width:99%;border-collapse:collapse;background-color:#ffffff;"&gt;
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;span style="font-size:11px;"&gt;Console.WriteLine(MyRound(1f));&amp;nbsp;&lt;/span&gt;&lt;span style="color:green;"&gt;//&amp;nbsp;prints&amp;nbsp;1&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;Console.WriteLine(MyRound(1.2f));&amp;nbsp;&lt;span style="color:green;"&gt;//&amp;nbsp;prints&amp;nbsp;1&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;Console.WriteLine(MyRound(1.5f));&amp;nbsp;&lt;span style="color:green;"&gt;//&amp;nbsp;prints&amp;nbsp;2&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;Console.WriteLine(MyRound(1.9f));&amp;nbsp;&lt;span style="color:green;"&gt;//&amp;nbsp;prints&amp;nbsp;2&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;Console.WriteLine(MyRound(2.1f));&amp;nbsp;&lt;span style="color:green;"&gt;//&amp;nbsp;prints&amp;nbsp;2&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
You&amp;#39;ll see that it now rounds to the proper number without using the Math.Round method. &lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191539.aspx</link><pubDate>Fri, 19 Jun 2009 17:02:16 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191539</guid><dc:creator>jmartingarcia</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191539.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191539</wfw:commentRss><description>&lt;br /&gt;
1.- Yes, you are right, I should create the rectangle outside the loop. &lt;br /&gt;
&lt;br /&gt;
2.- That won&amp;#39;t really work I think. You see, if the X position is the pixel 1.90 then should be the pixel 2 and not the pixel 1 on the screen.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; When I convert from world units to pixels I will get fractional pixels that I need to convert to the best matching pixel position.&lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191482.aspx</link><pubDate>Fri, 19 Jun 2009 13:39:11 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191482</guid><dc:creator>Craig Martin</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191482.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191482</wfw:commentRss><description>or if that code is a real performance problem&lt;br /&gt;
&lt;br /&gt;
instantiate the Rectangle outside the loop&lt;br /&gt;
&lt;br /&gt;
Rectangle rect = new Rectangle();&lt;br /&gt;
&lt;br /&gt;
then inside the loops do this&lt;br /&gt;
&lt;br /&gt;
rect.X = (int)X;&lt;br /&gt;
rect.Y = (int)Y;&lt;br /&gt;
etc&lt;br /&gt;
&lt;br /&gt;
so you are reusing the same object rather than instantiating a new one every time.&lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191481.aspx</link><pubDate>Fri, 19 Jun 2009 13:30:56 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191481</guid><dc:creator>Craig Martin</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191481.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191481</wfw:commentRss><description>The float64 (double) is coming from the Math.Round(..) call.&lt;br /&gt;
&lt;br /&gt;
Just do this.&lt;br /&gt;
&lt;br /&gt;
new Rectangle((int)X, ...)&lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191479.aspx</link><pubDate>Fri, 19 Jun 2009 13:27:36 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191479</guid><dc:creator>jmartingarcia</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191479.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191479</wfw:commentRss><description>I don&amp;#39;t know why the NProf does not want to work anymore. It runs the application but then after some seconds the application disappears and the profiler never stops.&lt;br /&gt;
&lt;br /&gt;
Well, anyway, the profiler said my application was taking about 20% of the time on the collision detection. The childs of the collision detection where basically the calculation of the rectangle coordinates and the creation of the rectangle. Ignoring the creation of the rectangle, the more consuming task was the Convert.ToInt32(float64), now I&amp;#39;m using float in my application but is float64 because I convert to In32 the Rounded number of my float, so the rectangle creation is like this:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new Rectangle(Convert.ToInt32(Math.Round( X )), ...)&lt;br /&gt;
&lt;br /&gt;
Now I&amp;#39;m thinking, I&amp;#39;m creating a rectangle for each sprite on the screen to check collision detection each Frame (update call) ... maybe I should create a rectangle once and then modify its properties on each frame.&lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191467.aspx</link><pubDate>Fri, 19 Jun 2009 13:06:58 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191467</guid><dc:creator>Craig Martin</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191467.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191467</wfw:commentRss><description>In most cases the readability hence smaller bug potential of foreach is preferable to the small performance difference, unless of course you must have the index, in which case the for statement is appropriate.&lt;br /&gt;
&lt;br /&gt;
But the garbage problem with lists that are constantly cleared and refilled every frame is said to be a problem on the 360 and in those cases it might be worth looking at using a fixed size array.&lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191449.aspx</link><pubDate>Fri, 19 Jun 2009 11:36:52 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191449</guid><dc:creator>Jeremy JANISZEWSKI</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191449.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191449</wfw:commentRss><description>Benjamin Nitschke has written an article on this :&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://benjaminnitschke.com/2009/04/22/ForVsForeachPerformance.aspx"&gt;http://benjaminnitschke.com/2009/04/22/ForVsForeachPerformance.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, a foreach + array seems to be the more efficient way to make an iteration (even if you convert a list to an array)</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191400.aspx</link><pubDate>Fri, 19 Jun 2009 05:23:16 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191400</guid><dc:creator>feal87</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191400.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191400</wfw:commentRss><description>Ah lol, anyway tried and same results.</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191399.aspx</link><pubDate>Fri, 19 Jun 2009 05:15:41 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191399</guid><dc:creator>Nick Gravelyn</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191399.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191399</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="http://forums.xna.com//Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;feal87:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="http://forums.xna.com//Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;Nick Gravelyn:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;Why not just use sw.Elapsed.TotalMilliseconds? There&amp;#39;s already a property that gives you the time in milliseconds with a decimal. :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsedmilliseconds.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsedmilliseconds.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;well, because its a long without decimals.&lt;br /&gt;The results are anyway the same but without decimals.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;That property you linked is not what I said. Look at it again: sw.Elapsed.TotalMillseconds. You get the Elapsed property from Stopwatch (which returns a TimeSpan) and then use the TotalMilliseconds property of that TimeSpan to get the total milliseconds with decimal place. :)</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191398.aspx</link><pubDate>Fri, 19 Jun 2009 05:07:24 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191398</guid><dc:creator>feal87</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191398.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191398</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="http://forums.xna.com//Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;Nick Gravelyn:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;Why not just use sw.Elapsed.TotalMilliseconds? There&amp;#39;s already a property that gives you the time in milliseconds with a decimal. :)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsedmilliseconds.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsedmilliseconds.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
well, because its a long without decimals.&lt;br /&gt;
The results are anyway the same but without decimals.</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191309.aspx</link><pubDate>Thu, 18 Jun 2009 23:54:30 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191309</guid><dc:creator>Nick Gravelyn</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191309.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191309</wfw:commentRss><description>Why not just use sw.Elapsed.TotalMilliseconds? There&amp;#39;s already a property that gives you the time in milliseconds with a decimal. :)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description></item><item><title>Re: C# Array[] speed vs List&lt;&gt; speed</title><link>http://forums.xna.com/forums/thread/191295.aspx</link><pubDate>Thu, 18 Jun 2009 23:04:24 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:191295</guid><dc:creator>feal87</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/191295.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=50&amp;PostID=191295</wfw:commentRss><description>3,167861 ms foreach array&lt;br /&gt;
9,075665 ms for array unoptimized&lt;br /&gt;
2,935359 ms for array optimized &lt;br /&gt;
20,38946 ms foreach list&lt;br /&gt;
17,04064 ms for list unoptimized&lt;br /&gt;
6,171315 ms for list optimized&lt;br /&gt;
&lt;br /&gt;
As i said they are very little differences between them, only the foreach list is the very slow one compared to the rest (9 times slower than the for over array optimized).&lt;br /&gt;
&lt;br /&gt;
P.S. the ms results are calculated this way. Can you confirm it is correct? &lt;br /&gt;
&lt;br /&gt;
&lt;div style="border-bottom:#7f9db9 1px solid;border-left:#7f9db9 1px solid;background-color:white;font-family:courier new;font-size:11px;overflow:auto;border-top:#7f9db9 1px solid;border-right:#7f9db9 1px solid;"&gt;
&lt;table style="border-bottom:#eee 0px solid;border-right-width:0px;background-color:#fff;margin:2px 0px;width:99%;border-collapse:collapse;border-top-width:0px;border-left-width:0px;" cellspacing="0" cellpadding="0"&gt;
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;span style="font-size:11px;"&gt;Results.Add(sw.ElapsedTicks * 1000f / Stopwatch.Frequency);  &lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;</description></item></channel></rss>