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.
  • C Christian Graus

    That's plain sad.

    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 )

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

    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

    C J 2 Replies Last reply
    0
    • C Christian Graus

      If my switch code was that complex, I'd have the switch call a method, which returned true or false, and use that return value to break or continue.

      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
      PIEBALDconsult
      wrote on last edited by
      #19

      Could also put the while in a method and return from the switch. Lots of ways to do it, various levels of cleanliness.

      C 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

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #20

        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 )

        F P 2 Replies Last reply
        0
        • P PIEBALDconsult

          Could also put the while in a method and return from the switch. Lots of ways to do it, various levels of cleanliness.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #21

          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 1 Reply Last reply
          0
          • P PIEBALDconsult

            Chris Losinger wrote:

            GC is part of C#

            No, it's part of .net. -- modified at 23:17 Thursday 4th October, 2007 the common language runtime (CLR)'s garbage collector http://msdn2.microsoft.com/en-us/library/ms973837.aspx[^]

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #22

            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 S 2 Replies 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 )

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

              Good point. But I believe that is more like taking good things from other languages, as long as they do not get in the way of the main language's goals. But yeah, I understand your point --and kinda agree with you.


              Hope is the negation of reality - Raistlin Majere

              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

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

                deos**troll**

                What else do you want from the guy?


                :badger:

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

                  deostroll wrote:

                  C++ with automatic garbage collection = C#

                  Next version of C++ standard comes with garbage collector. :cool:


                  Hope is the negation of reality - Raistlin Majere

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

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


                  :badger:

                  F 1 Reply Last reply
                  0
                  • 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
                                          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