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. General Programming
  3. C / C++ / MFC
  4. Virtual memory Problem [modified]

Virtual memory Problem [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++combusinessperformancehelp
10 Posts 5 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.
  • V Offline
    V Offline
    voorugonda prashanth
    wrote on last edited by
    #1

    Hi All, i have a vc++client and i'm using com components having business logic. Problem: i'll not close the client application. but the virtual memory accupied by the process is not freed. when it reaches maximum of virtual memory client application crashes. please give me the solution what to do avoid crashing. Thanks in Advance. Prashanth. -- modified at 2:58 Friday 2nd February, 2007

    J T 2 Replies Last reply
    0
    • V voorugonda prashanth

      Hi All, i have a vc++client and i'm using com components having business logic. Problem: i'll not close the client application. but the virtual memory accupied by the process is not freed. when it reaches maximum of virtual memory client application crashes. please give me the solution what to do avoid crashing. Thanks in Advance. Prashanth. -- modified at 2:58 Friday 2nd February, 2007

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      voorugonda prashanth wrote:

      the virtual memory accupied by the process is not freed.

      You are experiencing memory leaks. Are you using new (or, worse, malloc) without delete (or free)? Are you properly using delete[] when deleting an array? Are your COM-Components OK and properly releasing when no longer used? Are you sure you are releasing them?


      "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

      W 1 Reply Last reply
      0
      • V voorugonda prashanth

        Hi All, i have a vc++client and i'm using com components having business logic. Problem: i'll not close the client application. but the virtual memory accupied by the process is not freed. when it reaches maximum of virtual memory client application crashes. please give me the solution what to do avoid crashing. Thanks in Advance. Prashanth. -- modified at 2:58 Friday 2nd February, 2007

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        voorugonda prashanth wrote:

        when it reaches maximum of virtual memory client application crashes.

        i believe we cannot be much use for you as you urself have to debug the application to find cause of memory leaks

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

        1 Reply Last reply
        0
        • J jhwurmbach

          voorugonda prashanth wrote:

          the virtual memory accupied by the process is not freed.

          You are experiencing memory leaks. Are you using new (or, worse, malloc) without delete (or free)? Are you properly using delete[] when deleting an array? Are your COM-Components OK and properly releasing when no longer used? Are you sure you are releasing them?


          "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

          W Offline
          W Offline
          Waldermort
          wrote on last edited by
          #4

          jhwurmbach wrote:

          Are you using new (or, worse, malloc)

          Why would using malloc be wrose than using new? What do you think new is calling internally?

          J R 2 Replies Last reply
          0
          • W Waldermort

            jhwurmbach wrote:

            Are you using new (or, worse, malloc)

            Why would using malloc be wrose than using new? What do you think new is calling internally?

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #5

            WalderMort wrote:

            Why would using malloc be wrose than using new?

            malloc is very fine - in C-code. With C++ and objects, you better use new.

            WalderMort wrote:

            What do you think new is calling internally?

            How could I know? Why would I care? Thats an implementation detail that can (and will!) change. I have even seen an heap manager to be written from scratch.


            "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

            V 1 Reply Last reply
            0
            • W Waldermort

              jhwurmbach wrote:

              Are you using new (or, worse, malloc)

              Why would using malloc be wrose than using new? What do you think new is calling internally?

              R Offline
              R Offline
              Roger Stoltz
              wrote on last edited by
              #6

              A huge difference is that for an object the constructor is not guaranteed to be called when using ::malloc(), but it's guaranteed to be called when using new. The same goes for ::free() and delete. Read Stroustrup's FAQ for more info: clickety[^].


              "It's supposed to be hard, otherwise anybody could do it!" - selfquote

              W 1 Reply Last reply
              0
              • J jhwurmbach

                WalderMort wrote:

                Why would using malloc be wrose than using new?

                malloc is very fine - in C-code. With C++ and objects, you better use new.

                WalderMort wrote:

                What do you think new is calling internally?

                How could I know? Why would I care? Thats an implementation detail that can (and will!) change. I have even seen an heap manager to be written from scratch.


                "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

                V Offline
                V Offline
                voorugonda prashanth
                wrote on last edited by
                #7

                hi, i'm not using malloc or new in my application. i'm using only vectors of class objects allocated on stack itself. i dont see any problem with vectors of class objects allocating on stack. steps: 1) client application talks to the component 2) which internally talks DBHandler component which connects to SQL Server and returns the result back. 3) the result i'm storing in vectors for processing. 4) return back to the client. i'm not able get what exactly the problem is??

                J 1 Reply Last reply
                0
                • V voorugonda prashanth

                  hi, i'm not using malloc or new in my application. i'm using only vectors of class objects allocated on stack itself. i dont see any problem with vectors of class objects allocating on stack. steps: 1) client application talks to the component 2) which internally talks DBHandler component which connects to SQL Server and returns the result back. 3) the result i'm storing in vectors for processing. 4) return back to the client. i'm not able get what exactly the problem is??

                  J Offline
                  J Offline
                  jhwurmbach
                  wrote on last edited by
                  #8

                  voorugonda prashanth wrote:

                  dont see any problem with vectors of class objects allocating on stack.

                  Only when these objects are correctly copy-construcable. All objects in STL vectors will be copied when needed, and the old instances deleted. Some object may not properly delete their allocated resources when simply deleted and need to have a special deletion routine been called. Poor design, that. You say that you store results of an SQL-transaction. When this result does not hold a link to the SQL-connection and is simply data stored in members and not newed, I am also not able to get where the problem is. -- modified at 9:08 Friday 2nd February, 2007 typo


                  "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

                  1 Reply Last reply
                  0
                  • R Roger Stoltz

                    A huge difference is that for an object the constructor is not guaranteed to be called when using ::malloc(), but it's guaranteed to be called when using new. The same goes for ::free() and delete. Read Stroustrup's FAQ for more info: clickety[^].


                    "It's supposed to be hard, otherwise anybody could do it!" - selfquote

                    W Offline
                    W Offline
                    Waldermort
                    wrote on last edited by
                    #9

                    I know what the difference is between the two, but I would like to know why he thinks using malloc is worse than using new. Granted, using new has become the standard in c++ code, but there are instances where using malloc has proved to be better, take the resizing of dynamic arrays for example or needing to allocatate an instance without calling the c'tor ( not that I can think of a valid reason for doing this ).

                    R 1 Reply Last reply
                    0
                    • W Waldermort

                      I know what the difference is between the two, but I would like to know why he thinks using malloc is worse than using new. Granted, using new has become the standard in c++ code, but there are instances where using malloc has proved to be better, take the resizing of dynamic arrays for example or needing to allocatate an instance without calling the c'tor ( not that I can think of a valid reason for doing this ).

                      R Offline
                      R Offline
                      Roger Stoltz
                      wrote on last edited by
                      #10

                      WalderMort wrote:

                      but there are instances where using malloc has proved to be better

                      Sorry, WalderMort, I don't know what you're referring to by this statement. If you follow the link I provided in my previous post and scroll up a few lines, you will find this:

                      Stroustrup wrote:

                      There is no performance difference between malloc() and new when you take initialization into account.

                      In my humble opinion, if you find yourself in a situation where you think you benefit from the use of ::malloc() in C++, you're probably not using the language in the way Stroustrup intended. This is also how I interpret his statement a little bit further down:

                      Stroustrup wrote:

                      If you feel the need for realloc() - and many do - then consider using a standard library vector.

                      WalderMort wrote:

                      needing to allocatate an instance without calling the c'tor

                      I cannot possibly think that I will find myself in a situation where I actually want to use uninitalized data, the compiler would also complain about it. If you want to create a copy of an existing object, you don't use ::memcpy():omg: but you would rather use the copy constructor or the assignment operator. But that may be just me...:-> ...but I think not...


                      "It's supposed to be hard, otherwise anybody could do it!" - selfquote

                      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