472,342 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

A97: Why negative memory values reported?

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

'xxxxxxxxxxxxxxxBEGIN SNIPPETxxxxxxxxxxxxx
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 GlobalMemoryStatus Lib "kernel32" _
(lpBuffer As MEMORYSTATUS)

Private Sub Form_Load()

Dim MS As MEMORYSTATUS

MS.dwLength = Len(MS)
GlobalMemoryStatus MS

Label1.Caption = Format$(MS.dwMemoryLoad, "###,###,###,###") & " %
used"
Label2.Caption = Format$(MS.dwTotalPhys / 1024, "###,###,###,###")
& " Kbyte"
Label3.Caption = Format$(MS.dwAvailPhys / 1024, "###,###,###,###")
& " Kbyte"
Label4.Caption = Format$(MS.dwTotalPageFile / 1024,
"###,###,###,###") & " Kbyte"
Label5.Caption = Format$(MS.dwAvailPageFile / 1024,
"###,###,###,###") & " Kbyte"
Label6.Caption = Format$(MS.dwTotalVirtual / 1024,
"###,###,###,###") & " Kbyte"
Label7.Caption = Format$(MS.dwAvailVirtual / 1024,
"###,###,###,###") & " Kbyte"

End Sub

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

'xxxxxxxxxxxxxxxBEGIN SNIPPETxxxxxxxxxxxxx
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
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...
3
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...
5
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...
6
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...
33
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...
8
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#...
1
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...
11
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...
1
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...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.