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. Other Discussions
  3. IT & Infrastructure
  4. Opinion on Memory Allocation

Opinion on Memory Allocation

Scheduled Pinned Locked Moved IT & Infrastructure
performancequestion
5 Posts 3 Posters 0 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.
  • K Offline
    K Offline
    Kurt _B
    wrote on last edited by
    #1

    I started working with some source code where the original developers used pointers for almost every variable declaration, for instance. CRecordset* p = new CRecordset(); Is this a bad practice, besides the fact of possible memory leaks if it's not deleted? Thanks! Kurt

    K M 2 Replies Last reply
    0
    • K Kurt _B

      I started working with some source code where the original developers used pointers for almost every variable declaration, for instance. CRecordset* p = new CRecordset(); Is this a bad practice, besides the fact of possible memory leaks if it's not deleted? Thanks! Kurt

      K Offline
      K Offline
      Kevin McFarlane
      wrote on last edited by
      #2

      Recommended practice for modern C++ is to use pointers (i.e., explicit dynamic allocation) only when you have to. Otherwise declare an object on the stack or pass one by reference. It is almost certainly the case that in their code they are over-using pointers. These days I hardly ever explicitly allocate memory for pointers. When I do I use std::auto_ptr (though this is no good for pointers in collections - boost::shared_ptr helps out there or there are oher robust techniques). Other than that I use collection classes for data structures, e.g., MFC or STL. Kevin

      1 Reply Last reply
      0
      • K Kurt _B

        I started working with some source code where the original developers used pointers for almost every variable declaration, for instance. CRecordset* p = new CRecordset(); Is this a bad practice, besides the fact of possible memory leaks if it's not deleted? Thanks! Kurt

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        Kurt Barlar wrote: Is this a bad practice, besides the fact of possible memory leaks if it's not deleted? Yes, it also looks like the dev came from a Java background and doesn't know how to use C++ the right way. If that's the case, I'd be worried about missing deletes. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD

        K 1 Reply Last reply
        0
        • M Michael Dunn

          Kurt Barlar wrote: Is this a bad practice, besides the fact of possible memory leaks if it's not deleted? Yes, it also looks like the dev came from a Java background and doesn't know how to use C++ the right way. If that's the case, I'd be worried about missing deletes. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD

          K Offline
          K Offline
          Kurt _B
          wrote on last edited by
          #4

          Yes, memory leaks are a big problem.

          K 1 Reply Last reply
          0
          • K Kurt _B

            Yes, memory leaks are a big problem.

            K Offline
            K Offline
            Kevin McFarlane
            wrote on last edited by
            #5

            I've yet to do maintenance programming on a C++ application which doesn't have some non-trivial memory management bugs. This is probably because so many C++ developers code in the style of 10 years ago.:| Kevin

            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