Coffeehouse Post

Single Post Permalink

View Thread: MS working on a same compiler for C++ AND C# ! Not in 'incubation' but for production !
  • User profile image

    yeah, I do not follow at all how a C++ WinRT app is more efficient and less power using than C# when the majority of the time the app is in the WinRT.  And if a modern C++ app is supposed to use smart pointers, how is that more efficient that C# references?  I thought the lesson learned by the designers of the GC was that reference counting was slower than garbage collecting.

    But for an application where it makes sense to talk about performance *at all*, the majority of the time will *not* be spent in WinRT.

    But, and this is the important point, no one said anything about reference counting.

    Smart pointers != shared pointers.

    Shared pointers use reference counting, and they are *a* form of smart pointer. They are, by far, the slowest kind of smart pointer, and certainly not the first one you should look to.

    Most of the time, you can/should use something like unique_ptr, which is, well, optimal. There is literally no overhead to using it.

    And even smart pointers aren't the final word. They are just a single example of RAII. RAII is how *all* resources in C++ are managed. Not just memory, but sockets, files, locks and anything else.

    And resource management is not the reason why C++ can be faster than C#. The reason for *that* is that C++ supports a number of way to produce zero-overhead abstractions.


    So really, you're barking up the wrong tree. Overuse of shared pointers is one way in which (bad) C++ code can be made incredibly slow. But no one said to use shared pointers everywhere in modern C++ code. They said to use *smart pointers*.


    If you just tag a reference count onto every object in C++, then it's going to be slow. But in C++, you don't *need* to reference count the vast majority of objects, because you (and the compiler) *know* when they should be destroyed (hint: when they go out of scope)