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#
  4. Getting free physical Memory ?

Getting free physical Memory ?

Scheduled Pinned Locked Moved C#
performancehelpquestion
15 Posts 4 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.
  • M Martin 0

    Hello,

    Anton Afanasyev wrote:

    That's hardware, and hardware isnt downloadable

    :confused: Sorry but I don't even understand that joke? Maybe you can help next time.

    A Offline
    A Offline
    Anton Afanasyev
    wrote on last edited by
    #5

    gaaaah whats with people and no sense of humour. hmm, maybe its due to me having to be in bed by now... anyways, what i mean was that you were asking where you could get free RAM, and searching in google didnt help. as in, nobody willing to give you free ram. /me holds up "LAUGH NOW" sign...


    :badger:

    M 1 Reply Last reply
    0
    • B Bhupi Bhai

      Yes, I guess it's possible using SDK Memory related API's. Can't recall the exact API's though (had used them some 5yrs back :doh:), try finding them on MSDN. Hummm .... can recall of one called "GetSystemInfo" which returns info about current system. Good luck !! Regards, Bhupi Bhai.

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #6

      Thanks very much in advance! I'll give it a try (GetSystemInfo in kernel32.dll)! Martin

      1 Reply Last reply
      0
      • A Anton Afanasyev

        gaaaah whats with people and no sense of humour. hmm, maybe its due to me having to be in bed by now... anyways, what i mean was that you were asking where you could get free RAM, and searching in google didnt help. as in, nobody willing to give you free ram. /me holds up "LAUGH NOW" sign...


        :badger:

        M Offline
        M Offline
        Martin 0
        wrote on last edited by
        #7

        If it makes youre day better, I send you: :laugh::laugh:

        Anton Afanasyev wrote:

        whats with people and no sense of humour

        Maybe humor like that makes more fun if it is posted togetter with a real answer! All the best, Martin

        A 1 Reply Last reply
        0
        • B Bhupi Bhai

          Yes, I guess it's possible using SDK Memory related API's. Can't recall the exact API's though (had used them some 5yrs back :doh:), try finding them on MSDN. Hummm .... can recall of one called "GetSystemInfo" which returns info about current system. Good luck !! Regards, Bhupi Bhai.

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #8

          Hello, Had no luck with that. GetSystemInfo returns a:

          	\[StructLayout(LayoutKind.Sequential)\]
          	class SYSTEM\_INFO
          	{
          		public ushort wProcessorArchitecture;
          		public ushort wReserved;
          		public uint dwPageSize;
          		public IntPtr lpMinimumApplicationAddress;
          		public IntPtr lpMaximumApplicationAddress;
          		public IntPtr dwActiveProcessorMask;
          		public uint dwNumberOfProcessors;
          		public uint dwProcessorType;
          		public uint dwAllocationGranularity;
          		public ushort wProcessorLevel;
          		public ushort wProcessorRevision;
          	}
          

          I implemented it like that:

          	\[DllImport("kernel32.dll", CharSet = CharSet.Unicode,CallingConvention = CallingConvention.Winapi, EntryPoint = "GetSystemInfo")\]
          	private static extern void GetSystemInfo(\[In,MarshalAs(UnmanagedType.LPStruct)\]SYSTEM\_INFO pSysInfo);
          

          And called it like that:

          		SYSTEM\_INFO sysinfo = new SYSTEM\_INFO();
          		GetSystemInfo(sysinfo);
          

          But I didn't found a member that fits me needs:~ If I made something wrong, please let me know. But again thanks for youre time. Martin

          B 1 Reply Last reply
          0
          • M Martin 0

            Hello, Had no luck with that. GetSystemInfo returns a:

            	\[StructLayout(LayoutKind.Sequential)\]
            	class SYSTEM\_INFO
            	{
            		public ushort wProcessorArchitecture;
            		public ushort wReserved;
            		public uint dwPageSize;
            		public IntPtr lpMinimumApplicationAddress;
            		public IntPtr lpMaximumApplicationAddress;
            		public IntPtr dwActiveProcessorMask;
            		public uint dwNumberOfProcessors;
            		public uint dwProcessorType;
            		public uint dwAllocationGranularity;
            		public ushort wProcessorLevel;
            		public ushort wProcessorRevision;
            	}
            

            I implemented it like that:

            	\[DllImport("kernel32.dll", CharSet = CharSet.Unicode,CallingConvention = CallingConvention.Winapi, EntryPoint = "GetSystemInfo")\]
            	private static extern void GetSystemInfo(\[In,MarshalAs(UnmanagedType.LPStruct)\]SYSTEM\_INFO pSysInfo);
            

            And called it like that:

            		SYSTEM\_INFO sysinfo = new SYSTEM\_INFO();
            		GetSystemInfo(sysinfo);
            

            But I didn't found a member that fits me needs:~ If I made something wrong, please let me know. But again thanks for youre time. Martin

            B Offline
            B Offline
            Bhupi Bhai
            wrote on last edited by
            #9

            Yes, ur on the right track. But I am sorry can't recall the exact API for it. You will have to do some more rnd on this. Regards, Bhupi Bhai.

            M 1 Reply Last reply
            0
            • M Martin 0

              Hello, I would like to know if it's possible (and how) to get the free memory (RAM). I searched in google and here on the forum but had no luck so far. (It's also quit difficult to search for "free memory" ) Thanks for youre time and help, Martin

              L Offline
              L Offline
              lmoelleb
              wrote on last edited by
              #10

              I would suspect you can get the info though WMI. Using WMI from C# is fairly simple - you should be able to get a sample from Google. I would probably try to split the search into two: 1) How to use WMI from C# 2) How to get the free memory though WMI (in any language) just in case you can't easily find an example getting the free memory from C#.

              M 1 Reply Last reply
              0
              • L lmoelleb

                I would suspect you can get the info though WMI. Using WMI from C# is fairly simple - you should be able to get a sample from Google. I would probably try to split the search into two: 1) How to use WMI from C# 2) How to get the free memory though WMI (in any language) just in case you can't easily find an example getting the free memory from C#.

                M Offline
                M Offline
                Martin 0
                wrote on last edited by
                #11

                Hello, I think I found it 5minutes ago. But I will need it in future. Thank you. All the best, Martin

                B 1 Reply Last reply
                0
                • M Martin 0

                  Hello, I would like to know if it's possible (and how) to get the free memory (RAM). I searched in google and here on the forum but had no luck so far. (It's also quit difficult to search for "free memory" ) Thanks for youre time and help, Martin

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #12

                  Got it now!:-> Here is what I'm using now:

                  	\[StructLayout(LayoutKind.Sequential)\]
                  	class MEMORYSTATUS
                  	{
                  		public IntPtr dwLength;
                  		public IntPtr dwMemoryLoad;
                  		public IntPtr dwTotalPhys;
                  		public IntPtr dwAvailPhys;
                  		public IntPtr dwTotalPageFile;
                  		public IntPtr dwAvailPageFile;
                  		public IntPtr dwTotalVirtual;
                  		public IntPtr dwAvailVirtual;
                  	}
                  
                  	\[DllImport("kernel32.dll", CharSet = CharSet.Unicode,CallingConvention = CallingConvention.Winapi, EntryPoint = "GlobalMemoryStatus")\]
                  	private static extern void GlobalMemoryStatus(\[In,MarshalAs(UnmanagedType.LPStruct)\]MEMORYSTATUS lpBuffer);
                  

                  Maybe somebody needs it. Thanks for the replies. All the best, Martin

                  1 Reply Last reply
                  0
                  • B Bhupi Bhai

                    Yes, ur on the right track. But I am sorry can't recall the exact API for it. You will have to do some more rnd on this. Regards, Bhupi Bhai.

                    M Offline
                    M Offline
                    Martin 0
                    wrote on last edited by
                    #13

                    Found it! GlobalMemoryStatus from kernel32.dll Thanks again!

                    1 Reply Last reply
                    0
                    • M Martin 0

                      Hello, I think I found it 5minutes ago. But I will need it in future. Thank you. All the best, Martin

                      B Offline
                      B Offline
                      Bhupi Bhai
                      wrote on last edited by
                      #14

                      Yes, lmoelleb (is that ur name) is right. Using WMI in C# you can get Free Physical Memory. ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"); ManagementObjectCollection queryCollection1 = query.Get(); foreach(ManagementObject mo in queryCollection1 ) { Console.WriteLine("Free Physical Memory : " + mo["freephysicalmemory"].ToString()); } Regards, Bhupi Bhai.

                      1 Reply Last reply
                      0
                      • M Martin 0

                        If it makes youre day better, I send you: :laugh::laugh:

                        Anton Afanasyev wrote:

                        whats with people and no sense of humour

                        Maybe humor like that makes more fun if it is posted togetter with a real answer! All the best, Martin

                        A Offline
                        A Offline
                        Anton Afanasyev
                        wrote on last edited by
                        #15

                        The sad thing is, I replied to what I thought he meant...then later, adapted that answer to the situation. heh.I guess I deserved those 1 votes.


                        :badger:

                        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