Hacker News new | ask | show | jobs
by H3g3m0n 4653 days ago
I'm not an expert but in the gamedev domain, control over memory is fairly vital. It seems like it would be for lots of the other stuff C++ is used with too. In C++ I can allocate all my memory upfront in a pool since I know the exact size of my level, the number of objects and so on. Then use custom allocators/static for just about everything. When I make an object at runtime I can just snag preallocated space from the pool. With the ability to cast the pool's primitive data types to pointers I can even save on any need to index the blocks since I can use the unused memory to point to the next block of unused memory (although it's probably a minor optimization).

Go drops that control totally in favour of it's inbuilt garbage collector which the Go devs think they can just get right. That seems unlikely (the current implementation is apparently quite bad stop-the-world implementation).

Another issue that strikes me is library building. Afaik Go doesn't produce object that can be linked against by non-go stuff. C does this, it has a ABI.

This means I can write one library in C/C++ (and apparently Rust) and then have wrappers for just about every other programming language in existence. (Although C++ can make this painful with things like exceptions http://250bpm.com/blog:4 ).

It might be that Go's interfaces make it really useful for making Go libraries in, but some libraries need to be language agnostic as much as possible.

Many of the things Go initially solved over C++ are being chipped away too. I love reflection, it would be very useful for games, serialization and so on. C++ doesn't have it but there is a standards working group looking at it now, so we could see it in either C++14 in a year, or C++17 (probably with implementations before then). C++11 got threads and so on and there is a working group doing transactional memory, more threading stuff, networking and so on. So we could see something like Gorutines and Channels but still have access to low level things like raw memory barriers. C++ tooling is set to explode with what the clang people are up to.

Go seems great, but it does seem focused in the 'business' kind of domain. Maybe future versions could address some of the issues like the GC (either fixing it so it does meet the performance requirements, or allowing custom memory options, C# has the unsafe keyword for example).

EDIT: I note that Go might provide a package "unsafe" that could allow for some things like a custom GC but apparently would be hard to implement.

2 comments

  >in the gamedev domain, control over memory is fairly vital.
C# is taking over the game world. Most iOS games are, for instance, written in C# these days.

I have worked for a company who wrote a state-of-the-art 3D PC gaming engine in C#.

Being garbage collected doesn't remove the ability to manage memory. It just removes the need to call Malloc directly.

The fact that Unity uses C# as one of it's scripting engines doesn't mean that C# is taking over the game world (I'll assume that's where the C# reference is from - since Unity is incredibly popular for iOS devs). The vast majority of games are still C++, often scripted in Lua, Python, Javascript and C#.
I wouldn't describe Unity's relationship with C# as 'scripting'.

I realise that there are no doubt a number of custom C++ engines out there with embedded scripting languages but push for multi-platform mobile games has caused an huge shift towards Unity.

Maybe I'm moving in the wrong circled here — but anecdotally all the people I know making iOS & Android games are developing in Unity.

From the horse's mouth: http://answers.unity3d.com/questions/9675/is-unity-engine-wr...

And I don't doubt that alot of devs use Unity, it's most likely the most popular game engine. But it's still a C++ project, despite the languages used to script game events...

Xamarin
> "C# is taking over the game world. Most iOS games are, for instance, written in C# these days."

When the engine underneath is done in C# as well I will take that argument. So far, it would be the same that saying that most console games are done in UnrealScript.

Most iOS games aren't C# now a days. Unity likes to trot out the 70% number for mobile games but it's mostly bs. That isn't counting games that are actually published that based on there registered numbers, a lot of of never actually make it into the store. I'm willing to bet the most of iOS games are still Obj-C
I'd take that bet.

I know many iOS game developers and none of them use Objective-C any more.

(in fact I only ever knew one)

> state-of-the-art 3D PC gaming engine in C#.

How does it compare to Cry Engine, Unreal Engine, Frostbite, ...?

Because these are the state of the art gaming engines these days.

It compared surprisingly favourably. The C# engine was comparable (and regularly compared) to the Unreal Engine being used elsewhere in the company.

It was C# from the ground up. Scripting was provided via other .Net languages (Python in the case of the UI team).

Those are state of the art graphics gaming engines. It's quite hard to make e.g. an RTS using any of those. They are too FPS specific.
Command & Conquer is being built on Frostbite. [1]

[1] http://en.wikipedia.org/wiki/Command_%26_Conquer_(2013_video...

Are you referring to Unity? If so, while the game code is run via Mono, it is C++ internally.
Which is just some machine code eventually. It's just electric signals people!
Are you SURE about that?

Well, for shitty games maybe it is true, shovelware aplenty on iOS anyway.

But for the part of the market that actually has a profit (not just revenue) C# is not that dominant.

In terms of profit, the most profitable games probably still rely on C++.

Also most engines (including Unity) are made in C or C++, they sorta abstract the memory management for the game author, but they still do a lot of manual fiddling themselves, XNA for example (that allow you to write C# games directly to the hardware without a C++ engine) is notorious for bigger games having memory issues.

Also 2D "retina" games use so much absurd amounts of memory, that they are almost impossible to do purely in high-level languages, you need some C or C++ somewhere to handle them, at least texture loading, otherwise you end with loading times so big that people want to suicide.

Loading times don't have anything to do with the language.

Loading times have been an issue since game consoles moved away from cartridges.

I'm interested in knowing more about that engine. Can you say who/what it is?
Realtime Worlds
Ah, yes. Out of Boulder?

Which game's engine was in C#? Project MyWorld?

Yes. But out of Dundee, Scotland.
Memory management is extremely important for high-performance code. And C/C++ allow you complete control over it, but obviously with extra work needed to do this. But when you need the speed, it's so worth it, it's not funny.

On top of this, things like bit-packing and tagged-pointer type things can allow you to save memory, allowing you to fit more stuff into cachelines more efficiently, giving even more speedups.