Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:19:18+00:00 2026-05-26T08:19:18+00:00

I have been designing a component-based game library, with the overall intention of writing

  • 0

I have been designing a component-based game library, with the overall intention of writing it in C++ (as that is my forte), with Ogre3D as the back-end. Now that I am actually ready to write some code, I thought it would be far quicker to test out my framework under the XNA4.0 framework (somewhat quicker to get results/write an editor, etc). However, whilst I am no newcomer to C++ or C#, I am a bit of a newcomer when it comes to doing things the “XNA” way, so to speak, so I had a few queries before I started hammering out code:

  1. I read about using arrays rather than collections to avoid performance hits, then also read that this was not entirely true and that if you enumerated over, say, a concrete List<> collection (as opposed to an IEnumerable<>), the enumerator is a value-type that is used for each iteration and that there aren’t any GC worries here. The article in question was back in 2007. Does this hold true, or do you experienced XNA developers have real-world gotchas about this? Ideally I’d like to go down a chosen route before I do too much.

  2. If arrays truly are the way to go, no questions asked, I assume when it comes to resizing the array, you copy the old one over with new space? Or is this off the mark? Do you attempt to never, ever resize an array? Won’t the GC kick in for the old one if this is the case, or is the hit inconsequential?

  3. As the engine was designed for C++, the design allows for use of lambdas and delegates. One design uses the fastdelegate library which is the fastest possible way of using delegates in C++. A more flexible, but slightly slower approach (though hardly noticeable in the world of C++) is to use C++0x lambdas and std::function. Ideally, I’d like to do something similar in XNA, and allow delegates to be used. Does the use of delegates cause any significant issues with regard to performance?

  4. If there are performance considerations with regards to delegates, is there a difference between:

    public void myDelegate(int a, int b);
    private void myFunction(int a, int b)
    {
    }
    
    event myDelegate myEvent;
    
    myEvent += myFunction;
    

vs:

    public void myDelegate(int a, int b);

    event myDelegate myEvent;

    myEvent += (int a, int b) => { /* ... */ };

Sorry if I have waffled on a bit, I prefer to be clear in my questions. 🙂

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:19:19+00:00Added an answer on May 26, 2026 at 8:19 am

    Basically the only major performance issue to be aware of in C# that is different to what you have to be aware of in C++, is the garbage collector. Simply don’t allocate memory during your main game loop and you’ll be fine. Here is a blog post that goes into detail.

    Now to your questions:

    1) If a framework collection iterator could be implemented as a value-type (not creating garbage), then it usually (always?) has been. You can safely use foreach on, for example, List<>.

    You can verify if you are allocating in your main loop by using the CLR Profiler.

    2) Use Lists instead of arrays. They’ll handle the resizing for you. You should use the Capacity property to pre-allocate enough space before you start gameplay to avoid GC issues. Using arrays you’d just have to implement all this functionality yourself – ugly!

    The GC kicks in on allocations (not when memory becomes free). On Xbox 360 it kicks in for every 1MB allocated and is very slow. On Windows it is a bit more complicated – but also doesn’t have such a huge impact on performance.

    3) C# delegates are pretty damn fast. And faster than most people expect. They are about on-par with method calls on interfaces. Here and here are questions that provide more detials about delegate performance in C#.

    I couldn’t say how they compare to the C++ options. You’d have to measure it.

    4) No. I’m fairly sure this code will produce identical IL. You could disassemble it and check, or profile it, though.

    I might add – without checking myself – I suspect that having an event myDelegate will be slower than a plain myDelegate if you don’t need all the magic of event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on designing a file server that could take the load
I have been tasked with designing an ecommerce solution. The aspect that is causing
Assuming that best practices have been followed when designing a new database, how does
I have been writing some basic code for an application I am designing. I
I have been assigned on designing a java program on a linux machine that:
Designing an interface with QT4 I have been advised that using multiple Tabs at
I have been designing a game for a University project, and I thought it
I have been designing controls in Visual Studio 2008 and as you may have
I have been tasked with designing my web services client code to use the
So I have been working with javascript for a website I am designing, shocker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.