[vwnc] quick question: how to get system memory size?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
J G
Reply | Threaded
Open this post in threaded view
|

[vwnc] quick question: how to get system memory size?

J G
Hi,

I want to get the hardware RAM size in code, but don't know how to do so.  Any advice?Thanks.


Best Regards,

Jim G

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] quick question: how to get system memory size?

Boris Popov, DeepCove Labs (SNN)

Assuming you’re on win32, try something along the lines of,

 

Win32SystemSupport>>GlobalMemoryStatus: lpBuffer

                <C: void GlobalMemoryStatus(MEMORYSTATUS * lpBuffer)>

                ^self externalAccessFailedWith: _errorCode.

 

Win32SystemSupport>>MEMORYSTATUS

                <C: typedef struct _MEMORYSTATUS {

  DWORD dwLength;

  DWORD dwMemoryLoad;

  SIZE_T dwTotalPhys;

  SIZE_T dwAvailPhys;

  SIZE_T dwTotalPageFile;

  SIZE_T dwAvailPageFile;

  SIZE_T dwTotalVirtual;

  SIZE_T dwAvailVirtual;

} MEMORYSTATUS>

 

Win32SystemSupport>>getGlobalMemoryStatus

                "self new getGlobalMemoryStatus"

 

                | lpMemoryStatus |

                lpMemoryStatus := self MEMORYSTATUS gcMalloc.

                self GlobalMemoryStatus: lpMemoryStatus.

                ^(Win32MemoryStatus new)

                                load: (lpMemoryStatus memberAt: #dwMemoryLoad) asInteger;

                                totalPhysical: (lpMemoryStatus memberAt: #dwTotalPhys) asInteger;

                                availablePhysical: (lpMemoryStatus memberAt: #dwAvailPhys) asInteger;

                                totalPageFile: (lpMemoryStatus memberAt: #dwTotalPageFile) asInteger;

                                availablePageFile: (lpMemoryStatus memberAt: #dwAvailPageFile) asInteger;

                                totalVirtual: (lpMemoryStatus memberAt: #dwTotalVirtual) asInteger;

                                availableVirtual: (lpMemoryStatus memberAt: #dwAvailVirtual) asInteger;

                                yourself.

 

Smalltalk.OS defineClass: #Win32MemoryStatus

                superclass: #{Core.Object}

                indexedType: #none

                private: false

                instanceVariableNames: 'load totalPhysical availablePhysical totalPageFile availablePageFile totalVirtual availableVirtual '

                classInstanceVariableNames: ''

                imports: ''

                category: 'Win32 Available Memory'

 

-Boris

 

--

+1.604.689.0322

DeepCove Labs Ltd.

4th floor 595 Howe Street

Vancouver, Canada V6C 2T5

http://tinyurl.com/r7uw4

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Jim Guo
Sent: Monday, August 31, 2009 10:28 AM
To: vwnc
Subject: [vwnc] quick question: how to get system memory size?

 

Hi,

 

I want to get the hardware RAM size in code, but don't know how to do so.  Any advice?Thanks.



Best Regards,

Jim G


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
J G
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] quick question: how to get system memory size?

J G
Hi, Boris

It works. Thanks!

Best Regards,

Jim G


On Tue, Sep 1, 2009 at 1:38 AM, Boris Popov <[hidden email]> wrote:

Assuming you’re on win32, try something along the lines of,

 

Win32SystemSupport>>GlobalMemoryStatus: lpBuffer

                <C: void GlobalMemoryStatus(MEMORYSTATUS * lpBuffer)>

                ^self externalAccessFailedWith: _errorCode.

 

Win32SystemSupport>>MEMORYSTATUS

                <C: typedef struct _MEMORYSTATUS {

  DWORD dwLength;

  DWORD dwMemoryLoad;

  SIZE_T dwTotalPhys;

  SIZE_T dwAvailPhys;

  SIZE_T dwTotalPageFile;

  SIZE_T dwAvailPageFile;

  SIZE_T dwTotalVirtual;

  SIZE_T dwAvailVirtual;

} MEMORYSTATUS>

 

Win32SystemSupport>>getGlobalMemoryStatus

                "self new getGlobalMemoryStatus"

 

                | lpMemoryStatus |

                lpMemoryStatus := self MEMORYSTATUS gcMalloc.

                self GlobalMemoryStatus: lpMemoryStatus.

                ^(Win32MemoryStatus new)

                                load: (lpMemoryStatus memberAt: #dwMemoryLoad) asInteger;

                                totalPhysical: (lpMemoryStatus memberAt: #dwTotalPhys) asInteger;

                                availablePhysical: (lpMemoryStatus memberAt: #dwAvailPhys) asInteger;

                                totalPageFile: (lpMemoryStatus memberAt: #dwTotalPageFile) asInteger;

                                availablePageFile: (lpMemoryStatus memberAt: #dwAvailPageFile) asInteger;

                                totalVirtual: (lpMemoryStatus memberAt: #dwTotalVirtual) asInteger;

                                availableVirtual: (lpMemoryStatus memberAt: #dwAvailVirtual) asInteger;

                                yourself.

 

Smalltalk.OS defineClass: #Win32MemoryStatus

                superclass: #{Core.Object}

                indexedType: #none

                private: false

                instanceVariableNames: 'load totalPhysical availablePhysical totalPageFile availablePageFile totalVirtual availableVirtual '

                classInstanceVariableNames: ''

                imports: ''

                category: 'Win32 Available Memory'

 

-Boris

 

--

+1.604.689.0322

DeepCove Labs Ltd.

4th floor 595 Howe Street

Vancouver, Canada V6C 2T5

http://tinyurl.com/r7uw4

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Jim Guo
Sent: Monday, August 31, 2009 10:28 AM
To: vwnc
Subject: [vwnc] quick question: how to get system memory size?

 

Hi,

 

I want to get the hardware RAM size in code, but don't know how to do so.  Any advice?Thanks.



Best Regards,

Jim G




--
Best Regards,

Jim G

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc