Hacker News new | ask | show | jobs
by thecatspaw 3790 days ago
isnt the main problem with C#, Java and similars the garbage collector? which can at its worst kick in while you're in the middle of a fight or something. Even if its just 20ms, in a online FPS it potentially makes the difference between winning and loosing it.

edit: I am a Java guy myself, and would like to do some amateur gamedev in that direction (online FPS), but im worried about above mentioned point.

3 comments

Yes. Explicit control of memory is one of the big reasons C++ wins for high performance realtime applications like games.
True as far as it goes. Modern GC can mostly be done concurrently (it's only heap compaction that requires stopping the world). Fully pauseless GC is very much possible (see e.g. Azul C4), as are e.g. architectures involving multiple short-lived processes with individual heaps. Even without that, it's often possible to do a relatively small amount of manual work to do the things that require pausing only at appropriate times.
Possible != usable in production.
C4 is absolutely a production product. It's used in systems that insane amounts of money depend on. As for the manual approach, I've seen it work in production.
Well, not everyone is writing the next version of Crysis.

There are plenty of production games that can live with < 10ms pauses.

It's not just the pauses though. Cities Skyline has terrible performance, far worse than other more-intensive 3D games, and I can't help but feel that their choice of game engine is a major reason behind that.
The engine or the programmers?
Modern C# allows you to define a code path where GC is not allowed to run. I'm not sure if unity allows for this.

I'm also not sure about the new c# -> to native compilers coming out.

Could you link to the feature you're talking about? Unity uses a relatively ancient version of Mono IIRC, so it's unlikely that the feature is available in Unity unless your definition of "modern C#" is "after generics were added".
Modern C# means .NET 4.6

For example GC.TryStartNoGCRegion

https://msdn.microsoft.com/en-us/library/dn906201%28v=vs.110...

SafeBuffers

https://msdn.microsoft.com/library/system.runtime.interopser...

Or using array segments

https://msdn.microsoft.com/en-us/library/9cc4bx8k(v=vs.110)....

Unity has made a lot to spread C# love among game devs, but it also gave a bad reputation to those unaware how .NET really is.