Sign in to follow this  

C# and commercial games

This topic is 4309 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

Are commercial games still written in C++? or does most of them are written in C#? Is there a reason why to write a game in C++ rather then in C#? Another question, I already forgot that, but when does an allocated object may be released by the garbage collector? When there is no pointer pointing on him? If most of your objects are dynamically allocated, then you will have to nullify pointers in order for the objects pointed to them be released? Thanks in advance.

Share this post


Link to post
Share on other sites
Quote:
Original post by The C modest god
Are commercial games still written in C++? or does most of them are written in C#?
Is there a reason why to write a game in C++ rather then in C#?
Another question, I already forgot that, but when does an allocated object may be released by the garbage collector?
When there is no pointer pointing on him?
If most of your objects are dynamically allocated, then you will have to nullify pointers in order for the objects pointed to them be released?

Thanks in advance.


1) Most commercial games are written in C++.
2) Some are written in C#, check out Arena Wars.
3) Reasons for using C++ over C# include greater portability of code, slightly faster program execution (5% or more), or personal preference on languages.
4) Since there are no C style "Pointers" in C# (only references), the major way the garbage collector determines whether or not to release an object is by scope. However, there are several other methods the garbage collector uses.
5) No, you never have to nullify references to release memory nor should you. The garbage collector does a very good job figuring what objects you will need to reuse or what it can trash. If you want that kind of manual control over memory you should use C++. Otherwise, let the garbage collector do its job. That being said, there are ways to "coax" the garbage collector into getting rid of your objects. This is usually achieved through the use of scope or such tricks as the "using" keyword in C#.

Share this post


Link to post
Share on other sites
Quote:
Original post by Etherstar
Quote:
Original post by The C modest god
Are commercial games still written in C++? or does most of them are written in C#?
Is there a reason why to write a game in C++ rather then in C#?
Another question, I already forgot that, but when does an allocated object may be released by the garbage collector?
When there is no pointer pointing on him?
If most of your objects are dynamically allocated, then you will have to nullify pointers in order for the objects pointed to them be released?

Thanks in advance.


1) Most commercial games are written in C++.
2) Some are written in C#, check out Arena Wars.
3) Reasons for using C++ over C# include greater portability of code, slightly faster program execution (5% or more), or personal preference on languages.
4) Since there are no C style "Pointers" in C# (only references), the major way the garbage collector determines whether or not to release an object is by scope. However, there are several other methods the garbage collector uses.
5) No, you never have to nullify references to release memory nor should you. The garbage collector does a very good job figuring what objects you will need to reuse or what it can trash. If you want that kind of manual control over memory you should use C++. Otherwise, let the garbage collector do its job. That being said, there are ways to "coax" the garbage collector into getting rid of your objects. This is usually achieved through the use of scope or such tricks as the "using" keyword in C#.


What I tried to ask about the garbage collector is how does it knows you dont use an object anymore? Is there no dynamic allocation?
Obviously, the garbage collector cant release an object you are going to use in the future, even if you are not using it now.

Share this post


Link to post
Share on other sites
Quote:
Original post by The C modest god
Quote:
Original post by Etherstar
Quote:
Original post by The C modest god
Are commercial games still written in C++? or does most of them are written in C#?
Is there a reason why to write a game in C++ rather then in C#?
Another question, I already forgot that, but when does an allocated object may be released by the garbage collector?
When there is no pointer pointing on him?
If most of your objects are dynamically allocated, then you will have to nullify pointers in order for the objects pointed to them be released?

Thanks in advance.


1) Most commercial games are written in C++.
2) Some are written in C#, check out Arena Wars.
3) Reasons for using C++ over C# include greater portability of code, slightly faster program execution (5% or more), or personal preference on languages.
4) Since there are no C style "Pointers" in C# (only references), the major way the garbage collector determines whether or not to release an object is by scope. However, there are several other methods the garbage collector uses.
5) No, you never have to nullify references to release memory nor should you. The garbage collector does a very good job figuring what objects you will need to reuse or what it can trash. If you want that kind of manual control over memory you should use C++. Otherwise, let the garbage collector do its job. That being said, there are ways to "coax" the garbage collector into getting rid of your objects. This is usually achieved through the use of scope or such tricks as the "using" keyword in C#.


What I tried to ask about the garbage collector is how does it knows you dont use an object anymore? Is there no dynamic allocation?
Obviously, the garbage collector cant release an object you are going to use in the future, even if you are not using it now.


There is dynamic allocation and it's internally done for you. The GC knows you no longer need an object anymore when your program doesn't have any more references (pointers) to that object.


- xeddiex

Share this post


Link to post
Share on other sites
Quote:
Original post by Etherstar
4) Since there are no C style "Pointers" in C# (only references)...

Inaccurate. There are pointers in C#, but you may only use them within __unsafe blocks.

Quote:
Original post by The C modest god
What I tried to ask about the garbage collector is how does it knows you dont use an object anymore?

Reference counting. .NET: Automatic Memory Management: Releasing Memory, Component Object Model (COM): Managing Object Lifetime through Reference Counting.

Share this post


Link to post
Share on other sites
Quote:
Original post by The C modest god
Is there a reason why to write a game in C++ rather then in C#?


An important reason why C# is not used for most commercial games is because C# runs only on Microsoft Windows (yes, I know about the Mono attempt at providing a subset of the CLR, but it sure ain't there for games yet). The vast majority of games do not run under Microsoft Windows, but on consoles. If you were deciding on what technology to use to turn a profit, why would you choose one that prevents you from entering the most profitable sector of the marketplace?

If you decide to target PCs for your game, why would you want to alienate the Mac market, where people actually buy and pay for software and have already demonstrated they are willing to pay more for cache?

These are not technical reasons why C++ is preferred over C#, but in a commercial game profit trumps technology. For your own preference, that's another story.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
Quote:
Original post by The C modest god
Is there a reason why to write a game in C++ rather then in C#?


An important reason why C# is not used for most commercial games is because C# runs only on Microsoft Windows (yes, I know about the Mono attempt at providing a subset of the CLR, but it sure ain't there for games yet). The vast majority of games do not run under Microsoft Windows, but on consoles. If you were deciding on what technology to use to turn a profit, why would you choose one that prevents you from entering the most profitable sector of the marketplace?

If you decide to target PCs for your game, why would you want to alienate the Mac market, where people actually buy and pay for software and have already demonstrated they are willing to pay more for cache?

These are not technical reasons why C++ is preferred over C#, but in a commercial game profit trumps technology. For your own preference, that's another story.


What about developement time? Isnt that a major factor?
Most PC games also use DirectX only and so they are not protable anyway.
Maybe if you write a game to a console you would like later to prot it to the PC, but usually games written to the PC are not ported to the console.

Share this post


Link to post
Share on other sites
As a positive for C++, if you have trouble with a concept, you have the world to help you out; the C++ language has a huge following.

Not to mention, if you want to use someone else's library in a game (sound, input, anything), C++ is widely used.


discman1028

Share this post


Link to post
Share on other sites
Quote:
Original post by Etherstar
That being said, there are ways to "coax" the garbage collector into getting rid of your objects. This is usually achieved through the use of scope or such tricks as the "using" keyword in C#.


Actually the C# garbage collector doesn't even needs tricks or coaxing - Microsoft took a more realist approach to creating it, realizing that while 99% of the time you wouldn't want to handling it, 1% of the time it would be important.

Basically you can manually tell the garbage collector to free up memory instead of waiting for it to decide it must be done. There are even methods from the static collector object that lets you group object together - that way if you had some special code where you had to allocate a ton of little things in a loop, and knew you needed to free them before going to the next interation or suffer performance problems, you could get the garbage collector to cleanup just those objects (and leave other cleanup to when the collector decided it was most appropriate)


Overall C# is not used in most game programming for the same reason that C++ has only recently become the norm - the game industry is incredible slow to change from something that already works for them. The biggest reason is likely familiarity and skill. Sure, any decent programmer can "learn" C++ or C# in a month, but it takes a lot of time and practical experience before a programmer understands all the obscure little bits, and in game programmer there aren't many "it doesn't need to run that fast" situations like there are in business. The resulting high entry bar means it can take years before there are enough guru's of a language to supply the game industry in the quantity they need to justify using a new language. At the moment the community as a whole is still discovering the full depth of C# (see for example the great optimized C# game loop debate)

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Reference counting.


Just a nitpick - Reference counting, as traditionally defined, involves the programmer explicitly adding and removing references, which is not what .NET does.

Share this post


Link to post
Share on other sites

This topic is 4309 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this