473,574 Members | 3,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A97: Why negative memory values reported?

MLH
Am using code below to display memory
status. Problem with 4th and 5th ones
(dwTotalPageFil e and dwAvailPageFile ).
They show up as NEGATIVE. Why might
that be?

'xxxxxxxxxxxxxx xBEGIN SNIPPETxxxxxxxx xxxxx
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Private Declare Sub GlobalMemorySta tus Lib "kernel32" _
(lpBuffer As MEMORYSTATUS)

Private Sub Form_Load()

Dim MS As MEMORYSTATUS

MS.dwLength = Len(MS)
GlobalMemorySta tus MS

Label1.Caption = Format$(MS.dwMe moryLoad, "###,###,###,## #") & " %
used"
Label2.Caption = Format$(MS.dwTo talPhys / 1024, "###,###,###,## #")
& " Kbyte"
Label3.Caption = Format$(MS.dwAv ailPhys / 1024, "###,###,###,## #")
& " Kbyte"
Label4.Caption = Format$(MS.dwTo talPageFile / 1024,
"###,###,###,## #") & " Kbyte"
Label5.Caption = Format$(MS.dwAv ailPageFile / 1024,
"###,###,###,## #") & " Kbyte"
Label6.Caption = Format$(MS.dwTo talVirtual / 1024,
"###,###,###,## #") & " Kbyte"
Label7.Caption = Format$(MS.dwAv ailVirtual / 1024,
"###,###,###,## #") & " Kbyte"

End Sub

Nov 13 '05 #1
2 3163
MLH wrote:
Am using code below to display memory
status. Problem with 4th and 5th ones
(dwTotalPageFil e and dwAvailPageFile ).
They show up as NEGATIVE. Why might
that be?

'xxxxxxxxxxxxxx xBEGIN SNIPPETxxxxxxxx xxxxx
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type


It's what happens to long integers when you poke more than 2 gig into
them and nothing is error trapped, they wrap around. Internally the API
call is using unsigned integers. It fills the space with the right
number of 1s and 0s for an unsigned representation of the amount of RAM
you have, unfortunately VB only has signed integers so when the first
bit is a 1 then it's negative. If *you* try to poke more than 2 gigs
into a long int it will give you an overflow error as you're under the
control of VB.

A lot of API calls and even VB functions such as LOF() use long
integers, they were once sufficient but not in this day and age.

You can always check if <0 then add 2 gig and put result into another
data type but that only works if you know it's < 4GB as above that
figure it'll wrap around to the positive again, theoretically anyway as
I'd suspect a 4GB limitation might come into play here.

This is an age old problem that's happened before with disk space then
with RAM as 16 bit integers were used and used to wrap around at 32K.

I even remember a prime number finder I wrote years ago in DOS BASIC, it
would error at 32K then I'd switch to using a long int and error again
at 2 billion odd where I'd switch to using singles then doubles. This
was for speed reasons so the first few primes could be calculated
quickly (this really made a difference on a 12MHz 286). Once I compiled
the program to an EXE file it would just wrap. Putting in my own error
checking for overflows would have been expensive on CPU time so I ended
up just starting with doubles anyway. Never got far without getting
bored as you can imagine number crunching on a 286 :-\

--
[OO=00=OO]
Nov 13 '05 #2
MLH
Thanks, Trevor.

It's what happens to long integers when you poke more than 2 gig into
them and nothing is error trapped, they wrap around. Internally the API
call is using unsigned integers. It fills the space with the right
number of 1s and 0s for an unsigned representation of the amount of RAM
you have, unfortunately VB only has signed integers so when the first
bit is a 1 then it's negative. If *you* try to poke more than 2 gigs
into a long int it will give you an overflow error as you're under the
control of VB.

A lot of API calls and even VB functions such as LOF() use long
integers, they were once sufficient but not in this day and age.

You can always check if <0 then add 2 gig and put result into another
data type but that only works if you know it's < 4GB as above that
figure it'll wrap around to the positive again, theoretically anyway as
I'd suspect a 4GB limitation might come into play here.

This is an age old problem that's happened before with disk space then
with RAM as 16 bit integers were used and used to wrap around at 32K.

I even remember a prime number finder I wrote years ago in DOS BASIC, it
would error at 32K then I'd switch to using a long int and error again
at 2 billion odd where I'd switch to using singles then doubles. This
was for speed reasons so the first few primes could be calculated
quickly (this really made a difference on a 12MHz 286). Once I compiled
the program to an EXE file it would just wrap. Putting in my own error
checking for overflows would have been expensive on CPU time so I ended
up just starting with doubles anyway. Never got far without getting
bored as you can imagine number crunching on a 286 :-\


Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1434
by: Rick Brandt | last post by:
We are seeing performance problems running an A97 app on a new Terminal Server (Windows Server 2003) with Citrix MetaFrame XP. Our admin indicates that he has seen messages in other groups that say this is a bad combination. I'm just wondering if anyone here has experience with it and/or any suggestions. TIA
3
2156
by: Pieter Linden | last post by:
I have a database of rental units etc that I'm using the CreateTableFromRecordset code from ADH 2000. Well, at the moment, I'm doing a sanity check and testing it on my computer, with A2002, but anyway.... I'm trying to create is building by building (a table for each pair of buildings), so the format is something like this: Building ...
5
2338
by: MLH | last post by:
I have a line of code that works when called from a procedure in Access 2.0 form... PlaySound("C:\cr\help\Help0018.wav", 0) I imported what I thought was needed into A97. However, running it is unsuccessful. I get an error saying "file mmsystem not found". I think I've violated some API call protocol.
6
1848
by: MLH | last post by:
I have a command button with black letters on it. The default value in A97's forecolor property for that button is -2147483630. I didn't choose the color. That was the default when I created the button. I don't know of any negative color values. But, it seems to work and A97 insists on using the negative value. Why is that? And why not just...
33
3014
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have been for years. If the machine has memory to spare and windows can use it - I'm thinking "Why not?" I was wondering what some of you have to say...
8
4916
by: Afanasiy | last post by:
Should I be concerned with the amount of memory my C# applications use? I have 2 gigs of ram, and I use most of that without running any C# applications. So, when I see C# applications in development, which are using much more memory than their Delphi and Python equivalents, I am a bit worried. Is there more than meets the eye or is it...
1
2072
by: geskerrett | last post by:
I was wondering if a ctypes expert could point me in the right direction. I am using the wrapper for the "freeimage" library to create multipage TIFF files from a group of png images. The images load and save fine, the problem seems to be that the memory used during the bitmap creation isn't being released properly until the python program...
11
1971
by: The Frog | last post by:
Hi all, Maybe I am just missing something simple here, but I seem to have an issue with a callback function in A97 that is used to fill a Listbox with values. The first time the callback function is used (when the form opens) all runs well and everyone is happy. Then comes the problem - values are added to the recordset (ADO) that the...
1
2076
by: MLH | last post by:
Anyone remember if A97 append query failure would ever report data breaking validation rule when such was not the case. I have an old SQL statement - several years old now. I've encountered a case in which the append fails and the reported error is validation rule. The table being appended to (tblClusters) has only 1 field with a...
0
7804
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7721
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7811
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3740
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1057
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.