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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to know available memory?

How to know available memory?

Scheduled Pinned Locked Moved C#
performancehelptutorialquestion
11 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.
  • S Offline
    S Offline
    s196675m
    wrote on last edited by
    #1

    I like to know how much memory is available in the system before I allocate any memory block. Is there any class or way to get the current memory information from the system. Thanks you for your help.

    P E T realJSOPR 4 Replies Last reply
    0
    • S s196675m

      I like to know how much memory is available in the system before I allocate any memory block. Is there any class or way to get the current memory information from the system. Thanks you for your help.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      It could change between the time you check and the time you try to allocate anyway. Just try the allocation and catch the exception if any.

      1 Reply Last reply
      0
      • S s196675m

        I like to know how much memory is available in the system before I allocate any memory block. Is there any class or way to get the current memory information from the system. Thanks you for your help.

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        Allocate the minimum amount of memory necessary for the given task. Also, in c# a memory allocation should not fail unless it exceeds the allowable limit set by the framework for the application, the slowness will be OS based thrashing from VM.

        Need a C# Consultant? I'm available.
        Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

        S 1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          Allocate the minimum amount of memory necessary for the given task. Also, in c# a memory allocation should not fail unless it exceeds the allowable limit set by the framework for the application, the slowness will be OS based thrashing from VM.

          Need a C# Consultant? I'm available.
          Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

          S Offline
          S Offline
          s196675m
          wrote on last edited by
          #4

          Thanks for your suggession. Is there any way to know the amount of memory available programmatically even it might change from time to time. Just like taskbar, I like to know the snapshop of memory in any instance. Thank you again

          P 1 Reply Last reply
          0
          • S s196675m

            Thanks for your suggession. Is there any way to know the amount of memory available programmatically even it might change from time to time. Just like taskbar, I like to know the snapshop of memory in any instance. Thank you again

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            s196675m wrote:

            Just like taskbar

            Not a wheel I would reinvent.

            S 1 Reply Last reply
            0
            • P PIEBALDconsult

              s196675m wrote:

              Just like taskbar

              Not a wheel I would reinvent.

              S Offline
              S Offline
              s196675m
              wrote on last edited by
              #6

              Is there a way PROGRAMATICALLY( by code) to get memory information just like taskbar shows us.

              P 1 Reply Last reply
              0
              • S s196675m

                Is there a way PROGRAMATICALLY( by code) to get memory information just like taskbar shows us.

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                I heard you the first time. I don't know of anything in .net (though maybe someone else does), but maybe pInvoke this: http://msdn.microsoft.com/en-us/library/aa366589(VS.85).aspx[^] P.S. I just tried it, it works, I might write an article on it sometime.

                modified on Friday, May 16, 2008 11:10 PM

                S 1 Reply Last reply
                0
                • P PIEBALDconsult

                  I heard you the first time. I don't know of anything in .net (though maybe someone else does), but maybe pInvoke this: http://msdn.microsoft.com/en-us/library/aa366589(VS.85).aspx[^] P.S. I just tried it, it works, I might write an article on it sometime.

                  modified on Friday, May 16, 2008 11:10 PM

                  S Offline
                  S Offline
                  s196675m
                  wrote on last edited by
                  #8

                  Thank you for pointing me to the right API. I looked at the API's but I overlooked this function.

                  P 1 Reply Last reply
                  0
                  • S s196675m

                    Thank you for pointing me to the right API. I looked at the API's but I overlooked this function.

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    Glad to be of service.

                    1 Reply Last reply
                    0
                    • S s196675m

                      I like to know how much memory is available in the system before I allocate any memory block. Is there any class or way to get the current memory information from the system. Thanks you for your help.

                      T Offline
                      T Offline
                      The Nightcoder
                      wrote on last edited by
                      #10

                      Do you know how much memory you need to allocate or are you allocating "as much as you can" for some reason? If the former (you know what you need) - look at the System.Runtime.MemoryFailPoint in the later .NET versions. It was created to solve that need. If the latter (you don't) - consider rethinking your app. Seriously, stuff that does like that is a nuisance. Microsoft SQL Server and Exchange Server are two examples (using default settings). That's why they don't play well together in the same machine (without reconfiguring - and as Exchange requires direct Active Directory object property editing for that, it's even more of a nuisance). They keep fooling each others cache allocation strategies, and you end up with system requiring frequent restarts due to memory fragmentation.

                      -- Peter

                      1 Reply Last reply
                      0
                      • S s196675m

                        I like to know how much memory is available in the system before I allocate any memory block. Is there any class or way to get the current memory information from the system. Thanks you for your help.

                        realJSOPR Offline
                        realJSOPR Offline
                        realJSOP
                        wrote on last edited by
                        #11

                        Use System.Management and WMI API.

                        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                        -----
                        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                        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