Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 29 Jun 2004
Offline Last Active Today, 09:18 AM

#5015198 What kind of optimization makes C++ faster than C#?

Posted by Rattenhirn on 28 December 2012 - 04:15 PM

Productivity, not language performance, is the key feature.

Since this seems to be your primary argument now, I've spent some time looking into that.

Productivity is very difficult to quantify objectively, and in my experience the main productivity gain you get from C# is the excellent library that comes with it, especially for GUI programs. Hence it's high usefulness for tools.

But it like to hear more about those productivity gains!

#5014693 get colliding face of 2 AABB's?

Posted by Rattenhirn on 27 December 2012 - 08:01 AM

Yes, SAT can get pretty tricky, if more complex geometries are involved. Two AABBs are probably the second easiest, right after two spheres.


I found this website to be very helpful in explaining the theorem, it also has nifty interactive examples:




Unfortunately it only covers 2D collisions...

#5014691 What kind of optimization makes C++ faster than C#?

Posted by Rattenhirn on 27 December 2012 - 07:55 AM

GC is another topic that always pops up in these kind of discussions... IMO is pure non-sense. GC won't trigger if you don't "new" stuff, and will be VERY fast if you don't have objects with medium life expectancy.. it's just a matter to take some time to understand how the system works and how you can make it work for you... it's much easier to learn to deal with .NET's GC than learning proper memory management in C++, simple or through the 6-7 "smart" pointers available.
Just as you try to avoid new and delete in your game loop in C++, avoid newing class objects in C# and GC won't cause any troubles.

Dynamic memory management incurs by definition a certain amount of performance penalties. No matter what system is used, these penalties can be managed.

However, in a language that forces you to use one single tool for dynamic memory management, the garbage collector, limits one's flexibility in dealing with issues that arise quite a lot.

This is why languages that allow manual memory management will always have an edge in performance potential. Whether that's used is up to the programmers involved.

I don't think that in the future, general GCs will be that good, that manual memory management won't matter any more. After all, GCs also need to be implemented somehow. ;)

So what will happen (and is happening already, if you look close enough), is that manual and automatic memory management will be mixed.

you dont seem to understand how C# runtime works at all, so your claim are as wrong as it gets.
Every single C# function gets compiled to native code by the JIT the first time it is invoked, from that point on, that function is running native code period. So the "more work to do for every instruction" is just... uninformed and uninformative.
This has been the case for ages, since Java started doing it loooong time ago.

It's important to know that not all platforms allow emitting native code, because you either can't write to executable pages, can't change the executable flag on pages or the platform will only execute code signed with a secret key. This is especially true for the platforms we're usually dealing with in gamedev (consoles, smartphones, tablets).

In all of these cases, there's no (allowed) way to avoid using runtime interpretation of byte code.

It is possible, to "pre-JIT" byte code in some languages, but at that point you're basically back to a standard compiled language with a worse compiler.

Additionally, thanks to the LLVM project (and others like Cint or TCC), it's possible to JIT or interpret C and C++ source or byte code, closing this particular gap even more.

What remains is, that "cafe based" languages (Java, .net) need to assume a virtual machine to work properly. So runtime performance can only ever be as good as this virtual machine matches to the real machine used, causing more and more troubles as the virtual machine ages and the real machines progress.

Therefor, one will, all other things being equal, always pay a performance penalty when using languages targeting virtual machines. The question is how big this gap is. In my opinion, this performance penalty will shrink to almost zero over time, as JIT and regular compilers converge (again, see LLVM).

#5014661 get colliding face of 2 AABB's?

Posted by Rattenhirn on 27 December 2012 - 04:11 AM

SAT works by finding all the common axises (sp?) between the two colliders and see how much they overlap. If one of them doesn't overlap, there's no collision. Otherwise the collision normal can be devised from the overlaps.

AABB's, by definition, have the common axises global x, y and z. With the min/max tests you find out if all of them overlap or not. So what's left to do, is figure out, how much they overlap, and them simply pick the largest overlap, since the axises are also, by definition, the face normals.

I hope that helps!

And maybe someone can let me know what the correct plural of axis is... ;)

#5008791 Copyright protection, USB dongle?

Posted by Rattenhirn on 09 December 2012 - 08:25 AM

As far as I know these things are still around.

They're basically a secure key store. The key used to encrypt is stored inside the dongle and never put into the computers RAM, not unlike the
TPM, making it as secure as it gets.

Unfortunately this can't overcome the fundamental issue of all DRM systems, namely, that at some point the unencrypted data needs to be in the RAM of the computer in order to be useful, and it can always be extracted from there.

#5006742 Calling object constructors without using new

Posted by Rattenhirn on 03 December 2012 - 01:43 PM

But I would really like to have the actual object, and not a ptr to an object.
Is it possible, or am I forced to use pointers.

No need to use pointers, but you'll need to implement the default constructor of OtherClass like this:
[source lang="cpp"]class OtherClass{ OtherClass(); MyObject obj1; MyObject obj2;};OtherClass::OtherClass(): obj1("first name"), obj2("second name"){}[/source]

#5006592 New is SLOW!

Posted by Rattenhirn on 03 December 2012 - 07:41 AM

Your test cases are pretty use- and meaningless.

But your observation is essentially correct: Everything being equal, allocating on the stack is faster as allocating in the free store (or heap).

#5000940 Naughty Dog Company Profile

Posted by Rattenhirn on 14 November 2012 - 09:56 AM

I think your best (and pretty much only) bet is to get in contact with Naughty Dog Inc.:

#5000937 Virtual still the bad way ?

Posted by Rattenhirn on 14 November 2012 - 09:53 AM

My question is quite simple : Is virtual still bad on both console ?

The answer is really quite simple, independent of the platform:
If you do not need the decision at runtime, you do not need virtual or other decision structures and their performance cost and vice versa.

#4999857 Switch vs if else

Posted by Rattenhirn on 11 November 2012 - 03:49 AM

All other things being equal, switch expresses your intent more clearly. While it may not matter to the compiler, it will matter to readers of your code including your future self. Having a bunch of else ifs will force them to examine the whole construct in detail to hunt down the reason, why it is not a simple switch/case.

So, in short, prefer switch/case over else/ifs.

#4989494 Thread safe array

Posted by Rattenhirn on 12 October 2012 - 09:17 AM

It's very tough to build data structures that are thread safe in every conceivable use case and allow a wide variety of functionality.

If you really need to iterate over the array data, while other threads might be modifying it, then you have two options:
First, like you already said, make a copy and iterate over that. This won't work in all cases though, just imagine an array that stores pointers or references to objects. Those might not be valid anymore. Actually this is also an issue with all the methods that return elements of the array.

Secondly, acquire the array lock from the outside, iterate, release the lock. This works in any case, but requires the users of that array to know what they are doing...

#4989488 What Are a Game Designer Job Requirements?

Posted by Rattenhirn on 12 October 2012 - 09:02 AM


#4989394 Rock Band 3 piano support

Posted by Rattenhirn on 12 October 2012 - 02:48 AM

You can use all XBox peripherals on Windows, when you get one of these:

Then DirectInput / XInput, or whatever it's called now should give you access like to any other controller.

In addition, if I remember correctly, some game instruments have Midi output (the latest GH drum kit, the RB Fender guitar and very likely the keyboard), so you can go that route, which would automatically add support for _all_ midi based instruments.

Lastly, why wouldn it be legal to make a game that uses a rock band peripheral? In fact, on XBox you can play pretty much every game with those instruments, it's just not very pleasant. ;)

#4976726 Why even use virtual functions in a Parent class?

Posted by Rattenhirn on 05 September 2012 - 01:12 AM

What difference does the virtual function declaration in the Automobile class make? Couldn't I skip the declaration in automobile function since it is really not even a function (it does nothing) and just declare the function as normal in the Ferrari class? and if i made more child classes of the parent class Automobile, i could do the same?

Well, you could've just tried it out!

Anyway, here's the solution:
If you do not have a "drivespeed" function in "Automobile", your main would not compile.
If you'd make it not virtual, then your main would call the "drivespeed" function of the "Automobile" class and not of "Ferrari".
And that's exactly what polymorphism is. You can use a pointer to the base class to call a virtual function and it will automatically call the function implementation that matches the actual class.

Additionally, you state that the "drivespeed" function doesn't really make sense, because the speed of an "Automobile" is unknown. This can also be expressed in C++ by making the function "pure virtual".

That would look like this:
class Automobile
       virtual void drivespeed() = 0; // no implementation needed here

And lastly, the purpose of inheritance is not to avoid code duplication, but to semantically link classes with similar functionality.

I hope that helps!

#4975396 Anti-aliasing like Clear Type

Posted by Rattenhirn on 01 September 2012 - 05:18 AM

Two things:

1) Since this technique is a trade off, it only looks acceptable in certain situation. The most prominent is high contrast with sharp details (like black text on white background). In many other situations it would make matters worse, so the shader would have to be very very smart.

2) The technique is extensively covered by patents, which Microsoft owns.

So, in conclusion, you'd have to write a very sophisticated and expensive shader to gain minimal improvements on certain image areas, while trying to move around the parts covered by patents. Doesn't sound very nice to me! ;)