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. Memory usage

Memory usage

Scheduled Pinned Locked Moved C / C++ / MFC
performancetutorialquestion
6 Posts 6 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.
  • J Offline
    J Offline
    john5632
    wrote on last edited by
    #1

    How to check memory usage with in the application by itself?

    _ O D R A 5 Replies Last reply
    0
    • J john5632

      How to check memory usage with in the application by itself?

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #2

      You mean from inside the application, because if you want from outside, you can check it on TaskManager ...

      1 Reply Last reply
      0
      • J john5632

        How to check memory usage with in the application by itself?

        O Offline
        O Offline
        Orjan Westin
        wrote on last edited by
        #3

        On what operating system? If you want to keep track of total memory usage, you'll need a way to determine the size in memory of all code (e.g. application and dynamically linked libraries) and stack, which will vary depending on OS. For dynamic heap memory usage, you can make your own implementation of new/delete that counts allocated heap memory - this is the approach taken by memory leak detectors. Have a look at VLD which is an open-source memory leak detector for Visual C++.

        1 Reply Last reply
        0
        • J john5632

          How to check memory usage with in the application by itself?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          See here.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

          1 Reply Last reply
          0
          • J john5632

            How to check memory usage with in the application by itself?

            R Offline
            R Offline
            Rolf Kristensen
            wrote on last edited by
            #5

            CString csMsg;
            PROCESS_MEMORY_COUNTERS_EX procMemInfo = {0};
            procMemInfo.cb = sizeof(procMemInfo);
            if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&procMemInfo, sizeof(procMemInfo)))
            {
            // Log how much physical and total memory we are using
            // - Win7 (and newer) reports commit-size in this member
            if (procMemInfo.PagefileUsage==0)
            procMemInfo.PagefileUsage = procMemInfo.PrivateUsage;
            ULONG ulWorkingSetSize = (ULONG)(procMemInfo.WorkingSetSize / 1024 / 1024);
            ULONG ulPagefileUsage = (ULONG)(procMemInfo.PagefileUsage / 1024 / 1024);
            CString csProcessMemInfo;
            csProcessMemInfo.Format(_T("WorkingSetSize=%lu MBytes, CommitChargeSize=%lu MBytes"), ulWorkingSetSize, ulPagefileUsage);
            csMsg += csProcessMemInfo;
            }
            MEMORYSTATUSEX memStatus = {0};
            memStatus.dwLength = sizeof(memStatus);
            if (GlobalMemoryStatusEx(&memStatus))
            {
            // Log how much address space we are using (detect memory fragmentation)
            ULONG ulUsedVirtual = (ULONG)((memStatus.ullTotalVirtual-memStatus.ullAvailVirtual) / 1024 / 1024);
            ULONG ulAvailVirtual = (ULONG)(memStatus.ullAvailVirtual / 1024 / 1024);
            CString csMemStatus;
            csMemStatus.Format(_T("UsedVirtual=%lu MBytes, AvailableVirtual=%lu MBytes"), ulUsedVirtual, ulAvailVirtual);
            csMsg += csMemStatus;
            }

            1 Reply Last reply
            0
            • J john5632

              How to check memory usage with in the application by itself?

              A Offline
              A Offline
              Arun S J
              wrote on last edited by
              #6

              Use the API GetProcessMemoryInfo()

              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