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. How can I make my app to use less memory

How can I make my app to use less memory

Scheduled Pinned Locked Moved C / C++ / MFC
questioncssperformancehelp
4 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.
  • O Offline
    O Offline
    Ola Carlsson
    wrote on last edited by
    #1

    Hi, I have some problems with my apps memory usage. They use a lot of memory. How can I make my app to use less memory? Does it matter if I use semantic { CMyClass c; : } or { CMyClass *c; c = new CMyClass(); : delete c; } Do Windows use some kind of garbage collection? Then my app has been running for a while the memory usage is lesser. Why? Grateful for all help I can get. /Ola Carlsson, Sweden

    realJSOPR M 2 Replies Last reply
    0
    • O Ola Carlsson

      Hi, I have some problems with my apps memory usage. They use a lot of memory. How can I make my app to use less memory? Does it matter if I use semantic { CMyClass c; : } or { CMyClass *c; c = new CMyClass(); : delete c; } Do Windows use some kind of garbage collection? Then my app has been running for a while the memory usage is lesser. Why? Grateful for all help I can get. /Ola Carlsson, Sweden

      realJSOPR Online
      realJSOPR Online
      realJSOP
      wrote on last edited by
      #2

      The amount of memory required by a CMyClass object is the same, regardless of whether it's used on the stack or the heap. Garbage collection in VC++ is non-existant. If you use the heap, use it wisely. If I have a given object new'd/deleted many times, I will usually redesign the app so that the class is defined as a global variable and new'd in InitInstance, and deleted in the app destructor. Of course, this assumes that you don't need more than a single instance of the class object. Each app's requirements are different. Last item of note - I'm not sure if there's a limit on the size of the stack in a 32-bit program. In 16-bit days, it was 64k, so you had to be very careful of what data you put there. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends

      M 1 Reply Last reply
      0
      • O Ola Carlsson

        Hi, I have some problems with my apps memory usage. They use a lot of memory. How can I make my app to use less memory? Does it matter if I use semantic { CMyClass c; : } or { CMyClass *c; c = new CMyClass(); : delete c; } Do Windows use some kind of garbage collection? Then my app has been running for a while the memory usage is lesser. Why? Grateful for all help I can get. /Ola Carlsson, Sweden

        M Offline
        M Offline
        Mike Nordell
        wrote on last edited by
        #3

        Ola Carlsson wrote: Does it matter if I use semantic [...] Yes. If you're using heap memory your app will have larger memory footprint. There are a number of ways you can reduce the memory size of your executable, but they always boils down to: know what you're doing and what your compiler and runtime library is doing for you. Do Windows use some kind of garbage collection? Absolutely not. That's your responsibility. Then my app has been running for a while the memory usage is lesser. Why? There could be a number of reasons. One of them could be that you just looked at what was currently committed to RAM and not the total Working Set. When you minimize any app its working set is "trimmed" (SetProcessWorkingSetsize(-1, -1); IIRC).

        1 Reply Last reply
        0
        • realJSOPR realJSOP

          The amount of memory required by a CMyClass object is the same, regardless of whether it's used on the stack or the heap. Garbage collection in VC++ is non-existant. If you use the heap, use it wisely. If I have a given object new'd/deleted many times, I will usually redesign the app so that the class is defined as a global variable and new'd in InitInstance, and deleted in the app destructor. Of course, this assumes that you don't need more than a single instance of the class object. Each app's requirements are different. Last item of note - I'm not sure if there's a limit on the size of the stack in a 32-bit program. In 16-bit days, it was 64k, so you had to be very careful of what data you put there. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends

          M Offline
          M Offline
          Mike Nordell
          wrote on last edited by
          #4

          John Simmons / outlaw programmer wrote: Last item of note - I'm not sure if there's a limit on the size of the stack in a 32-bit program. There is no limit here, except when the virtual memory for stack bottom reaches something else (such as a heap). Then it will surely go down in flames. :-) It can AFAIK be changed by e.g. linker flags (changing the PE flags), but to my knowledge it has never been used in production applications.

          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