Running the same exes on the slower PC I get
VB6 563
VB2005 953
Faster PC runnign XP Pro SP3
Slower one running XP MCE SP2
Printable View
Running the same exes on the slower PC I get
VB6 563
VB2005 953
Faster PC runnign XP Pro SP3
Slower one running XP MCE SP2
Is that with Gremmy's code from post 284?Quote:
Originally Posted by WillAtwell
Yes and yours from 279Quote:
Originally Posted by WizBang
One small change made to Gremmy's code which may or may not be having an effect. The GetTickCount was not recognized in the designer and I changed it to Environment.TickCount.
Well, not knowing .net I can only guess there's some sort of "include" or something, so it would recognize the API call.
I did not see a gettickcount in the help index either nor any include in the code so I do nto know but since it is not inside the loop I would not think it made a noticable difference in the execution speed.
One other thing I just tested with very interesting results.
I moved the call to drawstuff in the dot net version to the form click event so I could repeat the test several times and get an average speed.
When executed this way I noticed that the VB6 exe varied between 15-23% processor usage and was hitting both cores of the cpu [as shown in task manager] Dot Net also hitting both cores at a load of 16-35%.
The interesting part was memory usage.
VB6 2.9 megs and held pretty steady no matter how many times I clicked the form.
Dot net 2008 build. started at 9 megs and increased by 7 megs with every click of the form. after a few clicks it had allocated over 120 megs of ram where the VB6 exe was still using under 3.
End result, the VB6 program was faster, used less resources and appeared as though it would be stable over time where as the dot net exe was slower, used more resources and gave the appearance that an out of memory error would occur if you allowed it to run long enough.
Wow, I knew .net would use more, but didn't expect so much, nor the compounding usage.
Not what I'd expect, unless you did nothing to destroy memory, and used NEW incorrectly.
I'd expect the Net version to get quicker after the first time thru.
Any idea if the garbage collection only occurs upon thread termination?Quote:
Originally Posted by dglienna
Just a simpleQuote:
Originally Posted by WizBang
Yes shoot me .. i should be using Pinvoke ... ;)Code:Private Declare Function GetTickCount Lib "kernel32" () As Long
Okay i think i may have sorted that out...Quote:
Originally Posted by WizBang
Adding this to the end of the code does a full cleanup, most of the memory was been used up by Me.BackgroundImage = New Bitmap(BmapBuffer).Code:c.Dispose()
If Not Me.BackgroundImage Is Nothing Then
Me.BackgroundImage.Dispose()
End If
Me.BackgroundImage = New Bitmap(BmapBuffer)
BufferGObj.Dispose()
BmapBuffer.Dispose()
That seemed to help, only adding 4 megs per click now was 7 beforeQuote:
Originally Posted by GremlinSA
I added the declare to the form and put back the gettickcount but it errored on the t=gettickcount with the message make sure you are not dividing by 0. :confused:Quote:
Originally Posted by GremlinSA
Post the code that you are using.
Oops my bad.Quote:
Originally Posted by WillAtwell
I missed removing one line and added the code after the new bitmap.
After I removed that first line above it would vary between 14 and 17 megs being allocated. While that is still 4-5 times what vb6 used at least it appears stable now.Code:Me.BackgroundImage = New Bitmap(BmapBuffer)
c.Dispose()
If Not Me.BackgroundImage Is Nothing Then
Me.BackgroundImage.Dispose()
End If
BufferGObj.Dispose()
BmapBuffer.Dispose()
This is what I had on the last run
Code:Public Class Form1
'Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
DrawStuff()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = 3
DrawStuff()
End Sub
Private Sub DrawStuff()
Dim Rct As Rectangle, W As Integer, H As Integer
Dim I As Integer, J As Integer, X1 As Integer, Y1 As Integer
Dim X2 As Integer, Y2 As Integer
Dim BmapBuffer As Image
Dim BufferGObj As Graphics
Dim T As Integer
T = Environment.TickCount
Rct.Size = Me.ClientSize
W = Rct.Width
H = Rct.Height
BmapBuffer = New Bitmap(W, H)
BufferGObj = Graphics.FromImage(BmapBuffer)
BufferGObj.Clear(Color.FromArgb(&H60, &H60, &H60))
Dim c As New Pen(Color.White)
J = CInt(TextBox1.Text)
If J < 1 Then J = 1
X2 = J
Y2 = J * 1.4
For X1 = 0 To W Step X2
For Y1 = 0 To H Step X2
'For I = 0 To J
c.Color = Color.FromArgb(X1 Mod 256, Y1 Mod 256, (X1 + Y1) Mod 256)
BufferGObj.DrawRectangle(c, X1, Y1, Y2 - 1, Y2 - 1)
'Next
Next
Next
Me.Text = Environment.TickCount - T
'Me.BackgroundImage = New Bitmap(BmapBuffer)
c.Dispose()
If Not Me.BackgroundImage Is Nothing Then
Me.BackgroundImage.Dispose()
End If
Me.BackgroundImage = New Bitmap(BmapBuffer)
BufferGObj.Dispose()
BmapBuffer.Dispose()
End Sub
End Class