Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: 95/98
Expertise: Beginner
Mar 16, 1998

Free System Resources

Question:
Is there an API call to find the amount of free system resources in Windows 95?

Answer:
Good news and bad news, here. Yes, there is. But, no, you can't call it from a 32-bit program.

The simple truth is, FSRs are a relic of another era. They have no meaning whatsoever under 32-bit Windows. But, you say, "Windows displays them!" Well, Win95 is a real mess under the hood. It's full of 16-bit code that really louses up the whole system, and makes FSRs still an issue, albeit less of one than before.

You can write a 16-bit OLE server with VB4, which makes the same old traditional Win16 calls to retrieve FSRs, if you find that you really need to. Below is a class module I wrote several years ago to do just that. Of course, if you're using VB3 you can still make the same API call, but you won't be able to wrap it up in a class like this.

Once you build this critter, just to show what I say above isn't a hoax, try querying FSRs in NT. You'll see that no matter what, all values are returned at 90%. The problem was, far too many programs wouldn't have known what to do if the OS told them the truth (100%). :-)

=== BOF: CFSR.CLS ===

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "CFreeSystemResources"
Attribute VB_Creatable = True
Attribute VB_Exposed = True
'
' Copyright (C)Karl E. Peterson, 1996
' All Rights Reserved.
'
Option Explicit
'
' Win16 declarations for FSR calls into ToolHelp
'
Private Type SYSHEAPINFO
   dwSize As Long
   wUserFreePercent As Integer
   wGDIFreePercent As Integer
   hUserSegment As Integer
   hGDISegment As Integer
End Type
Private Declare Function SystemHeapInfo Lib "toolhelp.dll" _
                          (shi As SYSHEAPINFO) As Integer
Private m_shi As SYSHEAPINFO

Private Sub Class_Initialize()
   '
   ' Initialize SYSHEAPINFO structure
   '
   m_shi.dwSize = Len(m_shi)
End Sub

Public Property Get UserFreePercent() As Integer
   '
   ' Retrieve FSR stats, and return User percent
   '
   Call SystemHeapInfo(m_shi)
   UserFreePercent = m_shi.wUserFreePercent
End Property

Public Property Get GdiFreePercent() As Integer
   '
   ' Retrieve FSR stats, and return GDI percent
   '
   Call SystemHeapInfo(m_shi)
   GdiFreePercent = m_shi.wGDIFreePercent
End Property

Public Property Get FSRPercent() As Integer
   '
   ' Retrieve FSR stats, and return lowest value
   '
   Call SystemHeapInfo(m_shi)
   If m_shi.wUserFreePercent < m_shi.wGDIFreePercent Then
      FSRPercent = m_shi.wUserFreePercent
   Else
      FSRPercent = m_shi.wGDIFreePercent
   End If
End Property
=== EOF: CFSR.CLS ===
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date