|
What did you define mVirtualMemory as? What's the return type on this function you created? The value returned by TotalVirtualMemory is an Unsigned Long (ULong), or a 64-bit unsigned integer. If the types you're using are smaller, like using 32-bit Integers, you can get some unexpected results.
Public Function GetTotalVMSizeInKb() As ULong
Dim x As ULong = My.Computer.Info.TotalVirtualMemory
Return (x / 1024)
End Function
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave,
Thank you for your reply, below is the full Property that I used in the class.
Public ReadOnly Property VirtualMemory() As ULong
Get
mVirtualMemory = My.Computer.Info.TotalVirtualMemory
mVirtualMemory = mVirtualMemory / 1024
Return mVirtualMemory
End Get
End Property
DB_Cooper1950
"Life is like a box of..."
|
|
|
|
|
You didn't specify what mVirtualMemory was before you used it, so it defaulted to an Integer type. Change it to this and it should work:
Public ReadOnly Property VirtualMemory() As ULong
Get
Dim vVirtualMemory As ULong = My.Computer.Info.TotalVirtualMemory
Return (mVirtualMemory / 1024)
End Get
End Property
Or, you can just avoid the entire variable declaration thing altogether and do this:
Public ReadOnly Property VirtualMemory() As ULong
Get
Return (My.Computer.Info.TotalVirtualMemory / 1024)
End Get
End Property
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">Dave Kreskowiak wrote:</div>You didn't specify what mVirtualMemory was before you used it, so it defaulted to an Integer type. Change it to this and it should work:</blockquote>
Dave,
Actually I did declare the variable mVirtualMemory as shown below. I just did not include this in the last entry.
...
Private mVirtualMemory As ULong
...
After that is when I used it here...
<code>
Public ReadOnly Property VirtualMemory() As ULong
Get
mVirtualMemory = My.Computer.Info.TotalVirtualMemory
mVirtualMemory = mVirtualMemory / 1024
Return mVirtualMemory
End Get
End Property
</code>
mVirtualMemory as you see is declared as a private ULong variable in the class that I wrote. So do you see anywhere else that I made a mistake?
Thank you.
DB_Cooper1950
"Life is like a box of..."
|
|
|
|
|
Nope. No other mistakes, save the only other one is your assuming you have a complete understanding of virtual memory under Windows. It's entirely possible to have this much "Virtual Memory", depending on your systems configuration. TotalVirtualMemory does NOT equal pagefile size!
Oh! And using a "global" variable like this (mVirtualMemory) is really bad practice! You're violating rules of Encapsulation and making it harder to debug your code. There is no reason, that I can see, for having that variable declared in Class scope. It should have been done inside the Property code.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave Kreskowiak wrote: Oh! And using a "global" variable like this (mVirtualMemory) is really bad practice! You're violating rules of Encapsulation and making it harder to debug your code. There is no reason, that I can see, for having that variable declared in Class scope. It should have been done inside the Property code.
Dave,
Please take a look at the following and then let me know that it is "Bad Practice", when the variable is used elsewhere in the class...
Public Class SystemMemory
#Region "Variables..."
Private mPhysicalMemory As Long
Private mVirtualMemory As ULong
Private mCombinedMemory As Long
Private mAvailablePhysicalMemory As Long
Private mAvailableVirtualMemory As ULong
Private mAvailableCombinedMemory As Long
Private mInstance As SystemMemory
Private mPctPhysicalMemory As Integer
Private mPctVirtualMemory As Integer
Private mPctCombinedMemory As Integer
#End Region
#Region "Constructors and Destructors..."
Public Sub New()
mInstance = Me
End Sub
Protected Overrides Sub Finalize()
mInstance = Nothing
End Sub
#End Region
#Region "Main Body in KB's..."
Public ReadOnly Property PhysicalMemory() As Long
Get
mPhysicalMemory = My.Computer.Info.TotalPhysicalMemory
mPhysicalMemory =(mPhysicalMemory / 1024)
Return mPhysicalMemory
End Get
End Property
Public ReadOnly Property VirtualMemory() As ULong
Get
mVirtualMemory = My.Computer.Info.TotalVirtualMemory
mVirtualMemory = mVirtualMemory / 1024
Return mVirtualMemory
End Get
End Property
Public ReadOnly Property CombinedMemory() As Long
Get
mCombinedMemory = (mPhysicalMemory + mVirtualMemory)
Return mCombinedMemory
End Get
End Property
....
I did not list where it is used elsewhere, but it is not just used inside the property call as the other private variables are also used elsewhere. Is is incorrect to call and use them in that manner?
DB_Cooper1950
"Life is like a box of..."
|
|
|
|
|
It is! Watch what happens when I get rid of all the class-scoped variables:
Public Class SystemMemory
' Say "Bye-Bye" to all the class-scoped variables! From what I can see in your code,
' you don't need a single one of them.
' I have no idea what you're doing with this stuff, but if the rest of this
' class is like your properties, you can get rid of this entire Region.
#Region "Constructors and Destructors..."
Public Sub New()
mInstance = Me
End Sub
Protected Overrides Sub Finalize()
mInstance = Nothing
End Sub
#End Region
#Region "Main Body in KB's..."
Public ReadOnly Property PhysicalMemory() As Long
Get
Return My.Computer.Info.TotalPhysicalMemory / 1024
End Get
End Property
Public ReadOnly Property VirtualMemory() As ULong
Get
Retrun My.Computer.Info.TotalVirtualMemory / 1024
End Get
End Property
Public ReadOnly Property CombinedMemory() As Long
' You can call your classes properties from inside
' the same class
Get
Return PhysicalMemory + VirtualMemory
End Get
End Property
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
You are absolutely correct, I could shave all of that "extra" stuff off, and have cleaner code with much less lines of code that could go wrong. But it hasn't changed the actual return value. And you are correct I am not fully versed in Virtual memory values, THAT is why I am asking for help.
Dave Baker
DB_Cooper1950
"Life is like a box of..."
|
|
|
|
|
OK. The memory functions under My.Computer.Info are actually calling a Win32 API function called GlobalMemoryStatusEx[^]. This function fills a structure called MEMORYSTATUSEX[^] that lists various measurements of the various types of memory managed by Windows, from the CURRENT PROCESSES point of view! This means that it measures memory based on your applications view of it, not the System Wide Windows view of memory! There is a HUGE difference...
When you call TotalPhysicalMemory and AvailablePhysicalMemory, you get the amount of physical memory reported by Windows, admittedly system-wide. But, this is NOT nocessarily all the physical memory in the machine. Some of it can be reserved by hardware for other functions, like shared video RAM.
Calls to TotalVirtualMemory and AvailableVirtualMemory return the status of YOUR processes virtual address space, which can be MORE than the amount of physical RAM available to Windows. You can typically have 2GB of memory available to each process, even though your machine only has say, 512MB of physical RAM.
How?? That's where the pagefile comes in. (Warning!! This explaination is very simplified!!) The pagefile is NOT virtual memory, but is a file that is used to store pages of memory that are allocated by all processes running in the system, combined. Say your machine has 512MB of RAM. The default pagefile size is 1.5x that size, or 768MB. So, if nothing is changed, Windows can have up to about 1.2GB of memory allocated acrossed all processes running in the system. But, it can only have 512MB of code and data in memory at any one time. Anything that is not being used, or the oldest memory pages that are still dirty, is swapped out to the pagefile to make room for pages that are needed.
WHen you launch your process, it gets a new virtual address space of 1.2GB. There are user-mode (for your application) and kernel-mode portions of that space. After all, you still need to be able to call into the Windows Kernel to do stuff, like open a file, and that Kernel code sits at the bottom of your VAS. Say the Kernel uses 200MB of memory. What's left, 1.0GB, is your user-mode space. This is what your application has left to allocate memory from.
Every process gets it's own virtual address space. Each process thinks that Windows and it are the only things running on the machine as far as memory goes! Each process thinks it gets about 1GB of RAM to play with, even though there is only 512MB in the system. Get it?
Now, if you called TotalVirtualMemory, it'll return something around 1GB. It only looks at the user-mode portion of your processes virtual address space, ignoring the kernel-mode portion. This is the value that your seeing in your code! I hope you can now see why there is no such thing as TotalVirtualMemory acrossed the entire system.
But, remember that pagefile size of 768MB? Well, there IS a limit to the amount of memory that can be allocated system-wide. If 2 processes tried to allocate 1GB of each, one of them would fail, even though it's address space says it can! Why?
Well, in our example, the pagefile can only hold 768MB worth of memory pages. Combined with physical memory, all the processes in the system can only allocate up to 1.2GB of memory, combined! Because of this, regardless of the virtual address space your process has, it's entirely possible that a process with a 1.2GB virtual address space can fail when it tries to allocate an object that takes 4KB of memory! Even though AvailableVirtualMemory said there was more...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave,
Thank you VERY much for that explaination, it makes a lot more sense to me now as to why I am not getting the exact amount of virtual memory that I thought that I was looking for. I realize that the explaination you gave was a simplified, but the point that you were trying to convey, was easier to understand that way, and for that I am grateful.
David Baker
DB_Cooper1950
"Life is like a box of..."
|
|
|
|
|
is there any control or functionality of any control that i can use to display data in hierarcal structure with multiple text boxes associated with each node? This is Very Urgent....
TC
-- modified at 9:19 Friday 27th October, 2006
|
|
|
|
|
Short of creating your own I'd say look at using a TreeView control with the LabelEdit property set to True.
|
|
|
|
|
But doing this , i have only one textbox on node and i want more than one textbox associated with each node. what to do?
TC
|
|
|
|
|
|
is it posible to add more than one textbox horizontally with each node? if yes then how?
TC
|
|
|
|
|
I had created application using VB 6.0 and Crystal report 8.5.
I want to install this application on client system, which does not have VB 6.0 and crystal report installed.
For VB application I will use deploymnet and package wizard.
But for crysatal report - how can I create set up.
Yor help is appreciated.
Thanks in Advance.
Kumar
-- modified at 3:25 Sunday 12th November, 2006
|
|
|
|
|
Good Day everyone,
i would like to ask for you help guys, i want to create a programs about
the circle packing, but dont know how to start with this, how can i draw equal circle without overlapping inside a bigger circle, i googled it but the result is discrete mathematics, im not a "math guy", so i cant understand those symbols..:=), thanks in advance for your help.. and GOD BLESS...
Kenshee
|
|
|
|
|
You'll want to use methods exposed from the Graphics Class[^] in the System.Drawing namespace.
Below is a quick sample I threw together - is this what you mean? Paste this code into a new form & run it.
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles Me.Paint
'draw three circles over each other
e.Graphics.FillEllipse(Brushes.Red, New Rectangle(0, 0, 300, 300))
e.Graphics.FillEllipse(Brushes.Blue, New Rectangle(25, 25, 250, 250))
e.Graphics.FillEllipse(Brushes.Green, New Rectangle(50, 50, 200, 200))
'dispose of the graphics object
e.Dispose()
End Sub
Private Sub Form1_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Resize
Me.Invalidate()
End Sub
End Class
|
|
|
|
|
may i know the way to fill the data from database to the combobox?
for datagrid the code is
datagridname.setDataBinding(dsStu, "StuTable")
then how about the combobox?
|
|
|
|
|
Create & fill a dataset object then use the combobox's DataSource and DisplayMember properties display data from the dataset.
|
|
|
|
|
|
Here is one way of binding data in combo box:
In code behind:
Dim ds As New DataSet
ds = class_Ratetype.ComboRateDisplay()
Dim dvs As New DataView(ds.Tables(0))
If dvs.Count > 0 Then
Me.ComboRoomType.DataSource = dvs
Me.ComboRoomType.DisplayMember = "Roomtype"
Me.ComboRoomType.ValueMember = "Roomtype_Id"
End If
End Sub
Class file content for this:
Public Function ComboRateDisplay() As DataSet
Dim constr As String = SqlHelper.GetConnectionString()
Dim conn As New SqlConnection(constr)
Dim cmdSQL As New SqlCommand("SP_COMBORATEDISPLAY", conn)
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim dv As New DataView
cmdSQL.CommandType = CommandType.StoredProcedure
conn.Open()
da.SelectCommand = cmdSQL
da.Fill(ds, "TBL_Roomtype")
ComboRateDisplay = ds.Copy
da.Dispose()
If (Not conn Is Nothing) Then
conn.Close()
conn.Dispose()
End If
GC.Collect()
End Function
For ur reference:
class_Ratetype ---> object for class file
ComboRoomType ----> combobox name
Roomtype ----> Display member
Roomtype_Id ----> Value member
SP_COMBORATEDISPLAY --> Stored procedure
TBL_Roomtype ----> Table name
Janani
|
|
|
|
|
I always do it like this:
comboBox1.DataSource = dtTable<br />
comboBox1.DisplayMember = "FieldToDisplay"<br />
comboBox1.ValueMember = "FieldContainingValue"
|
|
|
|
|
private sub num_KeyPress (ByVal sender......blah blah....)
If e.KeyChar < "0" or e.KeyChar > "9" then
e.handled = true
end if
end sub
can someone plz help iam only using the numbers and want to include the backspace button as well...
|
|
|
|
|
Try this:
...
If (e.KeyChar < '0' Or e.KeyChar > '9') And e.KeyChar <> '\b' Then
...
Additionally if using .NET 2.0 probably it would be better if you used PreviewKeyDown event:
Private Sub num_PreviewKeyDown(ByVal sender As Object, e As PreviewKeyDownEventArgs)
e.IsInputKey = ((e.KeyCode = Keys.Back) And (e.Modifiers = 0)) Or ((e.KeyCode >= Keys.D0 Or e.KeyCode <= D9 Or e.KeyCode >= Keys.NumPad0 Or e.KeyCode <= Keys.NumPad9) And (e.Modifiers = 0))
End Sub
This way you can handle key combinations like Alt + 0, Ctrl + Backspace, etc.
If using .NET 1.1 then use KeyDown to set a flag and check the flag value on the KeyPress event to set the Handled property.
- Xint0
|
|
|
|
|