473,421 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 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 3149
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 that he has seen messages in other groups that...
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 and testing it on my computer, with A2002, but...
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 thought was needed into A97. However, running it...
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 color. That was the default when I created 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 them) all the time for everything imaginable - have...
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# applications. So, when I see C# applications in...
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 TIFF files from a group of png images. The...
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 with values. The first time the callback...
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 - several years old now. I've encountered a case...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.