Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. C++ with automatic garbage collection = C#

C++ with automatic garbage collection = C#

Scheduled Pinned Locked Moved The Lounge
questioncsharpc++performance
87 Posts 31 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Anton Afanasyev

    deos**troll**

    What else do you want from the guy?


    :badger:

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #26

    Well yes, but if he's God's own troll...

    1 Reply Last reply
    0
    • N Nish Nishant

      PIEBALDconsult wrote:

      No, it's part of .net.

      Yeah but in a future version of the .NET framework, if it was a configurable option to turn off the GC (say via a GC::ShutDown() method), I am sure this wouldn't be a practical option for C#. Since C# does not have a syntactic equivalent of the C++ delete. You'd have to end up doing something weird like GCHandle::Delete(object) which would kill off C# popularity. So while GC is a part of .NET, people will always associate it with C#.

      Regards, Nish


      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
      My latest book : C++/CLI in Action / Amazon.com link

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #27

      Nishant Sivakumar wrote:

      people will always associate it with C#

      ... and perpetuate the misconception, I'm trying to clear the air. It's a windmill; I shall tilt at it.

      1 Reply Last reply
      0
      • A Anton Afanasyev

        I wonder how long it would take till the first Service Pack that fixes the memory leak in the GC for C++?


        :badger:

        F Offline
        F Offline
        Fernando A Gomez F
        wrote on last edited by
        #28

        Well, that'll depend on the compiler for C++, not the language itself.


        Hope is the negation of reality - Raistlin Majere

        A 1 Reply Last reply
        0
        • F Fernando A Gomez F

          Well, that'll depend on the compiler for C++, not the language itself.


          Hope is the negation of reality - Raistlin Majere

          A Offline
          A Offline
          Anton Afanasyev
          wrote on last edited by
          #29

          Well yeah. But what I meant is that the GC will most probably have a memory leak of its own.


          :badger:

          1 Reply Last reply
          0
          • C Christian Graus

            Sure - core issue is to refactor so a switch doesn't contan buckets of code. You should definately be able to easily see all the cases. And, I like to refactor code anyhow, to make for smaller, simpler methods.

            Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            R Offline
            R Offline
            Rei Miyasaka
            wrote on last edited by
            #30

            goto. *runs*

            S 1 Reply Last reply
            0
            • D deostroll

              What is the real difference, you ask? It is there in the title itself. Plus you may argue that c# is more typesafe and stuff; avoids any usually complex pointer logic; avoids pointers totally...yada yada yada... To me it is just the way c# language compiler was designed. When you come down to the compiler level you have to de-initialize an object and clear memory. No other way to do this. It may be a mammoth task in c++, but it is possible. Everything is possible. Those who say something is impossible are probably out of ideas (or lack of sample code maybe :confused:). Given indefinite time I believe developing applications in c++ would result in robust applications. However what most programmers do today is charge into the arena like a bull! I'd rather like to plan my path. And a piece of paper and a pen that writes is always a good start. I wonder who the hell said: time is money. I'd want to throw my pc at him, and say thankyou very much! It is what people are asking for. It is our society. Most of the time when customers ask developers to do something, they completely drop the ethical sense. The result of this is that you are being pressurized, unnecessarily; or worse the customers themselves pressurizing you, unnecessarily! For if it was the opposite case (i.e. the customers had this ethical knowledge) and they kept pressurizing you, there would at least be some sort of justice/sense in that! (You being nailed to the wall here is not the point). --deostroll

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #31

              deostroll wrote:

              It may be a mammoth task in c++, but it is possible.

              Possible yes, but practical no. Just as it's possible to walk from Boston to San Francisco, you'd probably fly or at least travel by car. /ravi

              This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

              1 Reply Last reply
              0
              • C Christian Graus

                Stroustrup was asked when Java came out what he thought of GC. His core answer was that GC would have killed C++, because of performance issues ( which may have been more real with the speed of processors then, than now ). There are a LOT of differences between C++ and C#. C++ has a better standard library, but C# offers support for things that C++ does not, such as regex. Yes, you can add those, I'm talking core language here. If anything, I think it's a shame C# looks like C++, when it's really very different in many ways.

                deostroll wrote:

                The result of this is that you are being pressurized, unnecessarily; or worse the customers themselves pressurizing you, unnecessarily!

                Really, the issue is that your client has no idea how long software takes, and a strong idea of when they want it. Explain the development triangle to them. Features, time, reliability. You can have two. Tell me which one to sacrifice to get the other two done.

                deostroll wrote:

                Given indefinite time I believe developing applications in c++ would result in robust applications.

                Given *reasonable* time, C++ results in robust applications.

                Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #32

                Christian Graus wrote:

                Features, time, reliability.

                Best two things I learned at a project management course were similar: 1) You can have at MOST two of the following: features, time, cost. Pick one or two that are flexible. The assumption here was that if a feature was to be included, reliability of that feature was not an option - the two went hand in hand. 2) Proposals should include a "what you don't get" section. What the customer won't be getting is just as important as what they will be getting. Cheers, Drew.

                1 Reply Last reply
                0
                • F Fernando A Gomez F

                  Well, it's optional. AFAIK, you'll have to place a modifier to the class, so only those classes' instances will be collected.


                  Hope is the negation of reality - Raistlin Majere

                  J Offline
                  J Offline
                  John M Drescher
                  wrote on last edited by
                  #33

                  I am glad of that as 99% of the time I have no use for a GC to slow my apps down.

                  John

                  1 Reply Last reply
                  0
                  • D deostroll

                    What is the real difference, you ask? It is there in the title itself. Plus you may argue that c# is more typesafe and stuff; avoids any usually complex pointer logic; avoids pointers totally...yada yada yada... To me it is just the way c# language compiler was designed. When you come down to the compiler level you have to de-initialize an object and clear memory. No other way to do this. It may be a mammoth task in c++, but it is possible. Everything is possible. Those who say something is impossible are probably out of ideas (or lack of sample code maybe :confused:). Given indefinite time I believe developing applications in c++ would result in robust applications. However what most programmers do today is charge into the arena like a bull! I'd rather like to plan my path. And a piece of paper and a pen that writes is always a good start. I wonder who the hell said: time is money. I'd want to throw my pc at him, and say thankyou very much! It is what people are asking for. It is our society. Most of the time when customers ask developers to do something, they completely drop the ethical sense. The result of this is that you are being pressurized, unnecessarily; or worse the customers themselves pressurizing you, unnecessarily! For if it was the opposite case (i.e. the customers had this ethical knowledge) and they kept pressurizing you, there would at least be some sort of justice/sense in that! (You being nailed to the wall here is not the point). --deostroll

                    Z Offline
                    Z Offline
                    Zdeslav Vojkovic
                    wrote on last edited by
                    #34

                    what's wrong with this one[^]? although, i believe that the well designed C++ program should extremely rarely exhibit problems with memory issues. The problem is that many devevelopers still write C using C++ compilers, so they malloc/free or new/delete bunch of stuff. I don't see why anyone would allocate memory for an array on the heap if there is std::vector. why would you explicitly delete something if you have std::auto_ptr or some smart pointer implementation (e.g. boost::shared_ptr)? Of course, i am aware that there are situations where you have to go 'classic' way, but that is minority, IMO.

                    J 1 Reply Last reply
                    0
                    • R Rei Miyasaka

                      goto. *runs*

                      S Offline
                      S Offline
                      SimonRigby
                      wrote on last edited by
                      #35

                      Stirrer :)

                      The only thing unpredictable about me is just how predictable I'm going to be.

                      1 Reply Last reply
                      0
                      • N Nish Nishant

                        PIEBALDconsult wrote:

                        No, it's part of .net.

                        Yeah but in a future version of the .NET framework, if it was a configurable option to turn off the GC (say via a GC::ShutDown() method), I am sure this wouldn't be a practical option for C#. Since C# does not have a syntactic equivalent of the C++ delete. You'd have to end up doing something weird like GCHandle::Delete(object) which would kill off C# popularity. So while GC is a part of .NET, people will always associate it with C#.

                        Regards, Nish


                        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                        My latest book : C++/CLI in Action / Amazon.com link

                        S Offline
                        S Offline
                        SimonRigby
                        wrote on last edited by
                        #36

                        Associate all you want. It ain't part of C#

                        The only thing unpredictable about me is just how predictable I'm going to be.

                        C 1 Reply Last reply
                        0
                        • C Christian Graus

                          Chris Losinger wrote:

                          GC is part of C# the same way vtables are part of C++. RegEx is an add-on in both

                          Nitpicking, one could say that is true. In the real world, C# doesn't really exist apart from the .NET framework. It's a bit like people assuming that MFC is part of C++, the difference is that in the C# world, there's no real world opposing viewpoint, no version of C# for which it's not true.

                          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                          S Offline
                          S Offline
                          SimonRigby
                          wrote on last edited by
                          #37

                          Christian Graus wrote:

                          Nitpicking, one could say that is true. In the real world, C# doesn't really exist apart from the .NET framework.

                          I think that's the point (or anti-point .. lol). Just because it has a close tie with the Framework doesn't mean the language doesn't exist in its own right. And for that matter the Framework lives on regardless of the existence or not of C#.

                          Christian Graus wrote:

                          It's a bit like people assuming that MFC is part of C++, the difference is that in the C# world, there's no real world opposing viewpoint, no version of C# for which it's not true.

                          But I take your point yes. The basic problem with C# is the name and name alone. Most criticisms of the C# language that I have read always seem to hark back to a comparison with C++. Why I don't know. I was at one time C programmer (a very ordinary hobbyist). When I started developing for a living I worked mostly with Java as that was what my "house" was using. Now I'm freelancing I tend towards C#. There are more similarities between Java and C# than C++ and C#. It seems that the existence of the letter C at the beginning has does something to relate the languages. I've often wondered why the name C# was chosen and I'm afraid the only conclusion I can come to is that it was a marketing decision. Let's face it most C developers would naturally be drawn to investigate a language called C++. In the same way could it not be said that same could hold true for C#?

                          The only thing unpredictable about me is just how predictable I'm going to be.

                          1 Reply Last reply
                          0
                          • C Christian Graus

                            Stroustrup was asked when Java came out what he thought of GC. His core answer was that GC would have killed C++, because of performance issues ( which may have been more real with the speed of processors then, than now ). There are a LOT of differences between C++ and C#. C++ has a better standard library, but C# offers support for things that C++ does not, such as regex. Yes, you can add those, I'm talking core language here. If anything, I think it's a shame C# looks like C++, when it's really very different in many ways.

                            deostroll wrote:

                            The result of this is that you are being pressurized, unnecessarily; or worse the customers themselves pressurizing you, unnecessarily!

                            Really, the issue is that your client has no idea how long software takes, and a strong idea of when they want it. Explain the development triangle to them. Features, time, reliability. You can have two. Tell me which one to sacrifice to get the other two done.

                            deostroll wrote:

                            Given indefinite time I believe developing applications in c++ would result in robust applications.

                            Given *reasonable* time, C++ results in robust applications.

                            Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                            J Offline
                            J Offline
                            Jan vd Borst
                            wrote on last edited by
                            #38

                            The only benefit of C# is the .net framework. Just like borlands VCL it is the framework and not the language (c++, delphi) that makes a technology worth while. Jan

                            P 1 Reply Last reply
                            0
                            • F Fernando A Gomez F

                              Christian Graus wrote:

                              The C# team says they are aiming to make the language as easy as possible, which is the exact opposite of the goal of the C++ team ( make it as powerful as it can be ).

                              That's why I don't like C#. IMO they are creating a monster with the language. As an example, do the yeild return thing adds power? No. But it makes it easy. It reminds me of all this keywords they added to VB6 (not comparing both languages though). They are just making it fancier, instead of giving power to the programmer. However, I wish the C++ library had more features. A GUI, for example, would be very nice. And XML and networking support. I know that the main goal is to make it portable, thus there may be devices that couldn't support this features. But what the hell, for these cases, they don't have to fulfill the standard (e.g. Embedded VC++ 3 didn't support exception handling). Any way, I'm still looking forward the next version of the standard.


                              Hope is the negation of reality - Raistlin Majere

                              J Offline
                              J Offline
                              jluber
                              wrote on last edited by
                              #39

                              Fernando A. Gomez F. wrote:

                              Christian Graus wrote: The C# team says they are aiming to make the language as easy as possible, which is the exact opposite of the goal of the C++ team ( make it as powerful as it can be ). That's why I don't like C#. IMO they are creating a monster with the language. As an example, do the yeild return thing adds power? No. But it makes it easy. It reminds me of all this keywords they added to VB6 (not comparing both languages though). They are just making it fancier, instead of giving power to the programmer.

                              What about anonymous functions and LINQ? Those do give more power, don't they?

                              F S 2 Replies Last reply
                              0
                              • D deostroll

                                What is the real difference, you ask? It is there in the title itself. Plus you may argue that c# is more typesafe and stuff; avoids any usually complex pointer logic; avoids pointers totally...yada yada yada... To me it is just the way c# language compiler was designed. When you come down to the compiler level you have to de-initialize an object and clear memory. No other way to do this. It may be a mammoth task in c++, but it is possible. Everything is possible. Those who say something is impossible are probably out of ideas (or lack of sample code maybe :confused:). Given indefinite time I believe developing applications in c++ would result in robust applications. However what most programmers do today is charge into the arena like a bull! I'd rather like to plan my path. And a piece of paper and a pen that writes is always a good start. I wonder who the hell said: time is money. I'd want to throw my pc at him, and say thankyou very much! It is what people are asking for. It is our society. Most of the time when customers ask developers to do something, they completely drop the ethical sense. The result of this is that you are being pressurized, unnecessarily; or worse the customers themselves pressurizing you, unnecessarily! For if it was the opposite case (i.e. the customers had this ethical knowledge) and they kept pressurizing you, there would at least be some sort of justice/sense in that! (You being nailed to the wall here is not the point). --deostroll

                                K Offline
                                K Offline
                                KLMR
                                wrote on last edited by
                                #40

                                Your simplification fails to grasp several key concepts that distinguish C++. I will just highlight one of these, because it is my favourite concept (and arguably the cornerstone to C++' success). I am speaking of templates. Yes, I know that C# has generics but these have not much in common with C++' powerful concept. C++ templates allow the implementation of very high abstraction data models and algorithms without any runtime penalty whatsoever! Take a look at any book on algorithms. Chances are, the examples are implemented in Java (unless, of course, you are reading Knuth, who, for reasons best known to himself, treats us to MIX). Now, these example codes usually practice a very high level of abstraction and present the concepts in a wonderfully concise way (once we overlook the shortcomings of Java's syntax). But, these books have a serious drawback: They trade abstraction for performance. Unfortunately, this trade-off is still (and will be for years to come) absolutely unacceptable in many computing areas. My own domain is bioinformatics and here the performance/abstraction trade-off of languages such as C#, VB or Java are clearly out of question. Templates in C++ offer the same degree of abstraction – in fact, the STL is a textbook example of abstraction and surpasses anything .NET or Java can muster – and the performance penalty (on modern compilers) equals zero. Good C++ compilers produce code having the same performance as hand-coded assembler routines, while using high abstraction. Stroustrup gives a very good example of the power of templates by comparing C++' std::sort function to qsort from C. Surprisingly, std::sort outperforms qsort even when their implementations are conceptually identical. This is due to the fact that qsort has to call a function pointer in order to compare elements. C++ achieves the same genericity through templates and a function object. This function object call can be inlined most of the time, eliding any runtime overhead. I have to address one other issue, though (because it figures in your thread title). C++ has no garbage collection for very good reasons. For those interested in details, I can advise looking up the RAII idiom and C++' way of treating objects as stack-located values most of the time (rather than working on pointers to the heap).

                                P J 2 Replies Last reply
                                0
                                • J Jan vd Borst

                                  The only benefit of C# is the .net framework. Just like borlands VCL it is the framework and not the language (c++, delphi) that makes a technology worth while. Jan

                                  P Offline
                                  P Offline
                                  Phil Martin
                                  wrote on last edited by
                                  #41

                                  For the most part I agree, but I've come across a number of cases where C#, for me, has nosed ahead over C++, and that is purely because of language features. The combination of delegates, events, and anonymous methods made implementing a number of low level systems that make no use of the framework (Except for the Delegate and Object classes :) ) The ease of using member functions as delegates is just so straight forward in C#, and using pointers to member functions in C++ is so incredibly painful without boost to help, it was a breath of fresh air. - Phil

                                  1 Reply Last reply
                                  0
                                  • C Christian Graus

                                    Either way, what's the point of having different languages, that are all the same ?

                                    Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                                    P Offline
                                    P Offline
                                    Phil Martin
                                    wrote on last edited by
                                    #42

                                    The most important reason of all! To give us all something to argue about when it's raining outside :)

                                    1 Reply Last reply
                                    0
                                    • K KLMR

                                      Your simplification fails to grasp several key concepts that distinguish C++. I will just highlight one of these, because it is my favourite concept (and arguably the cornerstone to C++' success). I am speaking of templates. Yes, I know that C# has generics but these have not much in common with C++' powerful concept. C++ templates allow the implementation of very high abstraction data models and algorithms without any runtime penalty whatsoever! Take a look at any book on algorithms. Chances are, the examples are implemented in Java (unless, of course, you are reading Knuth, who, for reasons best known to himself, treats us to MIX). Now, these example codes usually practice a very high level of abstraction and present the concepts in a wonderfully concise way (once we overlook the shortcomings of Java's syntax). But, these books have a serious drawback: They trade abstraction for performance. Unfortunately, this trade-off is still (and will be for years to come) absolutely unacceptable in many computing areas. My own domain is bioinformatics and here the performance/abstraction trade-off of languages such as C#, VB or Java are clearly out of question. Templates in C++ offer the same degree of abstraction – in fact, the STL is a textbook example of abstraction and surpasses anything .NET or Java can muster – and the performance penalty (on modern compilers) equals zero. Good C++ compilers produce code having the same performance as hand-coded assembler routines, while using high abstraction. Stroustrup gives a very good example of the power of templates by comparing C++' std::sort function to qsort from C. Surprisingly, std::sort outperforms qsort even when their implementations are conceptually identical. This is due to the fact that qsort has to call a function pointer in order to compare elements. C++ achieves the same genericity through templates and a function object. This function object call can be inlined most of the time, eliding any runtime overhead. I have to address one other issue, though (because it figures in your thread title). C++ has no garbage collection for very good reasons. For those interested in details, I can advise looking up the RAII idiom and C++' way of treating objects as stack-located values most of the time (rather than working on pointers to the heap).

                                      P Offline
                                      P Offline
                                      Phil Martin
                                      wrote on last edited by
                                      #43

                                      RAII and templates - seconded. While templates make it exceedingly easy to make some ugly code, used appropriately they are one of the most powerful and under-appreciated tools I've seen. And RAII - gee I miss that living in .Net land. The using keyword just doesn't scratch the same itch for me.

                                      1 Reply Last reply
                                      0
                                      • C Christian Graus

                                        Chris Losinger wrote:

                                        GC is part of C# the same way vtables are part of C++. RegEx is an add-on in both

                                        Nitpicking, one could say that is true. In the real world, C# doesn't really exist apart from the .NET framework. It's a bit like people assuming that MFC is part of C++, the difference is that in the C# world, there's no real world opposing viewpoint, no version of C# for which it's not true.

                                        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                                        C Offline
                                        C Offline
                                        Chris Losinger
                                        wrote on last edited by
                                        #44

                                        Christian Graus wrote:

                                        In the real world, C# doesn't really exist apart from the .NET framework.

                                        i'm a little disappointed to see that two people decided, in all the crap i wrote, to focus on that one throwaway analogy. :) oh well

                                        image processing toolkits | batch image processing

                                        1 Reply Last reply
                                        0
                                        • S SimonRigby

                                          Associate all you want. It ain't part of C#

                                          The only thing unpredictable about me is just how predictable I'm going to be.

                                          C Offline
                                          C Offline
                                          Chris Losinger
                                          wrote on last edited by
                                          #45

                                          read the spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf[^]. look up "garbage collection" - it's everywhere, it's non-optional, it's requirement of the langauge. now look up ".Net". there are three references: two in the first two paragraphs about the history of the language; and the other is in a code sample where the string ".Net" is part of an object specification. there's nothing in the spec that says "garbage collection is part of .Net, not C#". it is perfectly obvious that the people who wrote the C# spec think that GC is an intrinsic part of the C# language istelf.

                                          image processing toolkits | batch image processing

                                          S P 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups