473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

From C++ to C# and back again....

I taught myself C++ a while back, but never got to
involved in actually writing applications with it. I
actually spent the last 6 years working for numerous
internet web firms as well as doing a plethora of
freelance web development work. Lately I started learning
c#. The idea is to stop using coldfusion and switch to
writing c# using asp.net. The advantage I believe is that
I can develop websites and software that reuse code and
are tied together in a Solution. This idea is very
exciting to me.

One of my other passions and interests is game
development. I've looked around at a lot of different
websites and have read over and over again that although
game development with c# is possible; it's just not
pratical, due to peformance issues brought on by
using .net, etc.

It is my understanding, however, that as a .net
application runs the called functions are compiled to
native code through the JIT compiler. Only functions that
are called are compiled, but once compiled, are not
recompiled through the life of the program. In addition to
this, the compiled code is more effecient since it is
compiled specifically for the system and processor it is
running on. And typically speaking, as a .net program
runs; it gets faster and faster (obviously hitting a
plateau when all code is compiled).

If this is the case, wouldn't a game programmed
using .net, have better performance? Isn't it possible to
still use pieces of assembly code or otherwise unsafe code
for specific functions where performance is key?

I was looking at the Mangaged C++ port of the Quake II
engine the other day and was reading that "Running Quake
II.NET in the timedemo test indicates the managed version
performs about 85% as fast as the native version."
(http://www.vertigosoftware.com/Quake2.htm). The didn't do
much explaination as to why the managed version was
slower.

C# itself doesn't seem like it was meant for game
programming. Am I right? What advantages does the C++
language have over C# that makes it better for game
programming (as far as syntax goes, not performance)?

Thank you.
Nov 16 '05 #1
10 1199
Aaron,
You can use C# to develop games. It may be slightly slower than C++ (if
designed and implemented properly) be you will be much more productive.

Games developers are slow to move to C#. They already employ die hard C++
coders and there is a lot of snobbery regarding C#. Also C/C++ is used for
developing games for the consoles.

To start, try the following links.

Download the DirectX SDK
http://msdn.microsoft.com/library/de...st/directx.asp

Managed DirectX discussio
http://msdn.microsoft.com/newsgroups...&lang=en&cr=US

Managed DirectX eposide of the .NET Show
http://msdn.microsoft.com/theshow/Ep...37/default.asp

DirectX on MSD
http://msdn.microsoft.com/library/de...ch_directx.asp

Books on Managed Direct
http://www.amazon.com/exec/obidos/AS...9919604-591356
http://www.amazon.com/exec/obidos/AS...919604-5913560

Good luck.
Phil.

"Aaron" wrote:
I taught myself C++ a while back, but never got to
involved in actually writing applications with it. I
actually spent the last 6 years working for numerous
internet web firms as well as doing a plethora of
freelance web development work. Lately I started learning
c#. The idea is to stop using coldfusion and switch to
writing c# using asp.net. The advantage I believe is that
I can develop websites and software that reuse code and
are tied together in a Solution. This idea is very
exciting to me.

One of my other passions and interests is game
development. I've looked around at a lot of different
websites and have read over and over again that although
game development with c# is possible; it's just not
pratical, due to peformance issues brought on by
using .net, etc.

It is my understanding, however, that as a .net
application runs the called functions are compiled to
native code through the JIT compiler. Only functions that
are called are compiled, but once compiled, are not
recompiled through the life of the program. In addition to
this, the compiled code is more effecient since it is
compiled specifically for the system and processor it is
running on. And typically speaking, as a .net program
runs; it gets faster and faster (obviously hitting a
plateau when all code is compiled).

If this is the case, wouldn't a game programmed
using .net, have better performance? Isn't it possible to
still use pieces of assembly code or otherwise unsafe code
for specific functions where performance is key?

I was looking at the Mangaged C++ port of the Quake II
engine the other day and was reading that "Running Quake
II.NET in the timedemo test indicates the managed version
performs about 85% as fast as the native version."
(http://www.vertigosoftware.com/Quake2.htm). The didn't do
much explaination as to why the managed version was
slower.

C# itself doesn't seem like it was meant for game
programming. Am I right? What advantages does the C++
language have over C# that makes it better for game
programming (as far as syntax goes, not performance)?

Thank you.

Nov 16 '05 #2
Very nice response. Thank you. I was most interested in
the suggested books (I'm very good with self-teaching
using books), and it would seem (after reading many
comments) that most of the DX9 books have issues with
compiling code because of the latest updates of DX9 from
Microsoft.

What about OpenGL programming with C#? Is OpenGL still a
qualified competitor of DirectX? HL2 uses DX9 right? And
D3 uses OpenGL right?

-----Original Message-----
Aaron,
You can use C# to develop games. It may be slightly slower than C++ (ifdesigned and implemented properly) be you will be much more productive.
Games developers are slow to move to C#. They already employ die hard C++coders and there is a lot of snobbery regarding C#. Also C/C++ is used fordeveloping games for the consoles.

To start, try the following links.

Download the DirectX SDK
http://msdn.microsoft.com/library/default.asp? url=/downloads/list/directx.asp
Managed DirectX discussion
http://msdn.microsoft.com/newsgroups/default.aspx? dg=microsoft.public.win32.programmer.directx.manag ed&lang=e
n&cr=US
Managed DirectX eposide of the .NET Show
http://msdn.microsoft.com/theshow/Ep...37/default.asp

DirectX on MSDN
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dnanchor/html/anch_directx.asp
Books on Managed Direct X
http://www.amazon.com/exec/obidos/AS...25969/qid=1108 480784/sr=2-1/ref=pd_ka_b_2_1/104-9919604-5913560http://www.amazon.com/exec/obidos/AS...26612/qid=1108 480784/sr=2-2/ref=pd_ka_b_2_2/104-9919604-5913560
Good luck.
Phil.

"Aaron" wrote:
I taught myself C++ a while back, but never got to
involved in actually writing applications with it. I
actually spent the last 6 years working for numerous
internet web firms as well as doing a plethora of
freelance web development work. Lately I started learning c#. The idea is to stop using coldfusion and switch to
writing c# using asp.net. The advantage I believe is that I can develop websites and software that reuse code and
are tied together in a Solution. This idea is very
exciting to me.

One of my other passions and interests is game
development. I've looked around at a lot of different
websites and have read over and over again that although game development with c# is possible; it's just not
pratical, due to peformance issues brought on by
using .net, etc.

It is my understanding, however, that as a .net
application runs the called functions are compiled to
native code through the JIT compiler. Only functions that are called are compiled, but once compiled, are not
recompiled through the life of the program. In addition to this, the compiled code is more effecient since it is
compiled specifically for the system and processor it is running on. And typically speaking, as a .net program
runs; it gets faster and faster (obviously hitting a
plateau when all code is compiled).

If this is the case, wouldn't a game programmed
using .net, have better performance? Isn't it possible to still use pieces of assembly code or otherwise unsafe code for specific functions where performance is key?

I was looking at the Mangaged C++ port of the Quake II
engine the other day and was reading that "Running Quake II.NET in the timedemo test indicates the managed version performs about 85% as fast as the native version."
(http://www.vertigosoftware.com/Quake2.htm). The didn't do much explaination as to why the managed version was
slower.

C# itself doesn't seem like it was meant for game
programming. Am I right? What advantages does the C++
language have over C# that makes it better for game
programming (as far as syntax goes, not performance)?

Thank you.

.

Nov 16 '05 #3
What about my question concerning assembly and unsafe code; I haven't
gotten to unsafe code in my c# book yet, can assembly code be used in a
c# application where peformance is imperative?

Nov 16 '05 #4
Aaron,
Personally, I've never looked at OpenGL. Suggest you try the following links.

http://www.opengl.org/
http://www.taoframework.com/
http://www.codeproject.com/csharp/csopengl.asp
http://sourceforge.net/project/showf...group_id=33241

Regards,
Phil.

"Aaron" wrote:
Very nice response. Thank you. I was most interested in
the suggested books (I'm very good with self-teaching
using books), and it would seem (after reading many
comments) that most of the DX9 books have issues with
compiling code because of the latest updates of DX9 from
Microsoft.

What about OpenGL programming with C#? Is OpenGL still a
qualified competitor of DirectX? HL2 uses DX9 right? And
D3 uses OpenGL right?

-----Original Message-----
Aaron,
You can use C# to develop games. It may be slightly

slower than C++ (if
designed and implemented properly) be you will be much

more productive.

Games developers are slow to move to C#. They already

employ die hard C++
coders and there is a lot of snobbery regarding C#. Also

C/C++ is used for
developing games for the consoles.

To start, try the following links.

Download the DirectX SDK
http://msdn.microsoft.com/library/default.asp?

url=/downloads/list/directx.asp

Managed DirectX discussion
http://msdn.microsoft.com/newsgroups/default.aspx?

dg=microsoft.public.win32.programmer.directx.manag ed&lang=e
n&cr=US

Managed DirectX eposide of the .NET Show
http://msdn.microsoft.com/theshow/Ep...37/default.asp

DirectX on MSDN
http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/dnanchor/html/anch_directx.asp

Books on Managed Direct X
http://www.amazon.com/exec/obidos/AS...25969/qid=1108

480784/sr=2-1/ref=pd_ka_b_2_1/104-9919604-5913560
http://www.amazon.com/exec/obidos/AS...26612/qid=1108

480784/sr=2-2/ref=pd_ka_b_2_2/104-9919604-5913560

Good luck.
Phil.

"Aaron" wrote:
I taught myself C++ a while back, but never got to
involved in actually writing applications with it. I
actually spent the last 6 years working for numerous
internet web firms as well as doing a plethora of
freelance web development work. Lately I started learning c#. The idea is to stop using coldfusion and switch to
writing c# using asp.net. The advantage I believe is that I can develop websites and software that reuse code and
are tied together in a Solution. This idea is very
exciting to me.

One of my other passions and interests is game
development. I've looked around at a lot of different
websites and have read over and over again that although game development with c# is possible; it's just not
pratical, due to peformance issues brought on by
using .net, etc.

It is my understanding, however, that as a .net
application runs the called functions are compiled to
native code through the JIT compiler. Only functions that are called are compiled, but once compiled, are not
recompiled through the life of the program. In addition to this, the compiled code is more effecient since it is
compiled specifically for the system and processor it is running on. And typically speaking, as a .net program
runs; it gets faster and faster (obviously hitting a
plateau when all code is compiled).

If this is the case, wouldn't a game programmed
using .net, have better performance? Isn't it possible to still use pieces of assembly code or otherwise unsafe code for specific functions where performance is key?

I was looking at the Mangaged C++ port of the Quake II
engine the other day and was reading that "Running Quake II.NET in the timedemo test indicates the managed version performs about 85% as fast as the native version."
(http://www.vertigosoftware.com/Quake2.htm). The didn't do much explaination as to why the managed version was
slower.

C# itself doesn't seem like it was meant for game
programming. Am I right? What advantages does the C++
language have over C# that makes it better for game
programming (as far as syntax goes, not performance)?

Thank you.

.

Nov 16 '05 #5
No it can't.

From MSDN: "In unsafe code it is possible to declare and operate on
pointers, to perform conversions between pointers and integral types, to
take the address of variables, and so forth"

That's pretty much it I'm afraid. However you could easily write the parts
of your program that required assembler in managed C++, and call that
assembly from your C# code...

"paradox" <de*@demiurgeinc.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
What about my question concerning assembly and unsafe code; I haven't
gotten to unsafe code in my c# book yet, can assembly code be used in a
c# application where peformance is imperative?

Nov 16 '05 #6
With the benefits of C# in mind, would it make sense to develop a game
mostly in C# and use managed and unmanaged c++ where necessary for
peformance? Would doing so effectively "cure" the performance issues
associated with using .NET for game programming?

To clarify my question. The purpose of using c# in such a case would be
for the ease of use provided by the syntax of the language and using
unmanaged code would be to avoid the cost of garbage collection and
have direct control over memory management. Are there enough advantages
in the syntax of the c# language to decide to write a game that uses it
in conjunction with c++ or would it just make more sense to soley use
c++?

As an alternative approach, would it be possible to develop the engine
in c++ and write the game code in c#? Thank you.

Nov 16 '05 #7
Hi...

I think the former would work the best. In my experience (15 yrs)
developing software, one tenet has worked well for me... "make it work -
then make it work fast."

It is very difficult if near impossible to determine where your code is
spending its time -- so the only way to know where to optimize it to write
the code (in C#), profile it, then re-write the most-used routines in C/C++
or assembly to get the speed that you need.

You may find, however, that the managed code works just fine and that you do
not need to use unmanaged code at all.

John Puopolo

PS. I'd be interested in how this turns out -- post and let us know!

"paradox" <de*@demiurgeinc.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
With the benefits of C# in mind, would it make sense to develop a game
mostly in C# and use managed and unmanaged c++ where necessary for
peformance? Would doing so effectively "cure" the performance issues
associated with using .NET for game programming?

To clarify my question. The purpose of using c# in such a case would be
for the ease of use provided by the syntax of the language and using
unmanaged code would be to avoid the cost of garbage collection and
have direct control over memory management. Are there enough advantages
in the syntax of the c# language to decide to write a game that uses it
in conjunction with c++ or would it just make more sense to soley use
c++?

As an alternative approach, would it be possible to develop the engine
in c++ and write the game code in c#? Thank you.

Nov 16 '05 #8
thb
Yes it can.

You can't add assembly code inside a C# project, since there is no
machine code in a .NET executable. However, you can create an external
DLL in asm, and call its functions from your managed C#.

This solution is very efficient if you don't switch too often from
managed C# to platform assembly. It ruins the supposed portability
advantages of C#, though.

Nov 16 '05 #9
Well most games are written in C or C++ and include pieces of assembly
and other code. Almost all of which are not platform independent. By
developing the majority of the project in c#, the components developed
in unmanaged c++ or platform assembly would be the only aspects of the
application that I would need to develop for each platform. This
correct?

I'm sure most games have other conventions they used to narrow down the
amount of code they need to rewrite for each platform; anyone have any
insight into what these conventions are? Thanks.

Nov 16 '05 #10
Your last sentence, that "You may find ... that the managed code works just
fine", is so true.

I just finished a program where I was doing processing on daily stock
prices, and had 30 years of data to process. I was afraid that this thing
would take days or weeks to do its job, but the managed code could run
through the entire 3.9 million records in about 15 minutes. Rewriting it
for greater speed would have been a waste of my time. Had it taken 15 hours
to do this work, I'd be rewriting it, but at 15 minutes per run it just
doesn't merit extra effort on my part.

It all depends on what you are doing. Managed .NET code is not necessarily
"slow" code relative to your needs, it all depends on what you are doing and
what your requirements are.

On a different part of the same project, I was writing code that hit the
same data over-and-over, and there was a lot of data to hit. In this case,
the key to speed was processing chunks of data that fit into the CPU cache.
When processing 30 MB of data, the speed was 8 loops per second, when
processing 600 KB of data the speed was 2000 loops per second. The extra
hit to read the data from disk in small chunks was trivial compared to the
speedup by getting all my data into the processor's 1 MB cache. A 20 hour
(projected) processing time was cut to 20 minutes. If you see actual
numbers and have a sense for what you are trying to do, you can sometimes
get improvements like this. The two hours of coding I did to rewrite my
algorithm were paid back in my first run of the data.

I'll add one more thought ... the very biggest returns to optimization come
from finding something that you don't actually have to do, and not doing it.
Making "uselessRepetitiveRoutine()" run at maximum speed is no where near as
effective as not calling it in the first place. Every now and then, this
tip makes all the difference.

Tad

"John Puopolo" <jo**********@fastsearch.com.nospam> wrote in message
news:eG**************@TK2MSFTNGP12.phx.gbl...
Hi...

I think the former would work the best. In my experience (15 yrs)
developing software, one tenet has worked well for me... "make it work -
then make it work fast."

It is very difficult if near impossible to determine where your code is
spending its time -- so the only way to know where to optimize it to write
the code (in C#), profile it, then re-write the most-used routines in
C/C++
or assembly to get the speed that you need.

You may find, however, that the managed code works just fine and that you
do
not need to use unmanaged code at all.

John Puopolo

Nov 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
8
by: Galahad | last post by:
Here's the question: I have a form w/ TextBox controls and a Search Button control. Once the user clicks the Search Button, they get a Modal dialog w/ a datagrid that contains their search...
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
15
by: tshad | last post by:
I was looking for a way to handle refreshes (user pressed refresh button) and found a piece of code to check if a Web page was refreshed but I can't get it to work. The code is:...
7
by: mohammed.naghman | last post by:
Hi, I have 2 submit buttons in a jsp page. One of them takes me to page2.jsp and also passes the values enetered to page2.I have a link in the page2 that does a history.back to come to the...
3
by: Tom | last post by:
Basically I have a page that I load with 10 input fields. If users have JS enabled I want to hide 5 of these fields so as to reduce clutter. If the user needs these extra fields an "Add" button can...
6
by: John | last post by:
Hi I have a button which calls a method which in turn calls another method, which in turn calls another method. Let's say in the third method an error occurs and it is no longer possible to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.