Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Vb.Net (Flushing/Clearing) Ram & CPU Source Code

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
RecycledTwice
How do I cheat?
Reputation: 0

Joined: 01 Dec 2013
Posts: 6
Location: Tennessee

PostPosted: Wed Sep 28, 2016 8:00 pm    Post subject: Vb.Net (Flushing/Clearing) Ram & CPU Source Code Reply with quote

Original Source By: AfaoMax (Improvised by: Me RecycledTwice)
this will help your program drastically, as far as ram resources and cpu usage.

x1 - Timer (set to enabled, tick set to 1)

Code:


Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal process As IntPtr, ByVal minimumWorkingSetSize As Integer, ByVal maximumWorkingSetSize As Integer) As Integer

Public Class Form1

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Timer1.Start()

     End Sub

     Public Sub FlushMemory()

        Try

            GC.Collect(1, GCCollectionMode.Optimized) 'The Bit in parenthesis Was added by me
            GC.GetTotalMemory(False)
            GC.WaitForPendingFinalizers()

            If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then

                SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)

                Dim myProcess As Process
                Dim myProcesses As Process() = Process.GetProcessesByName("YourAppName.exe")

                For Each myProcess In myProcesses

                    SetProcessWorkingSetSize(myProcess.Handle, -1, -1)

                Next myProcess

            End If

        Catch ex As Exception

           MessageBox.Show(ex.Message, "YourAppName", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

     End Sub

     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        FlushMemory()
        Timer1.Interval = 1

     End Sub

End Class


_________________
Relatively new to cheat engine and scripting but trying to learn & more.......Hope to help contribute.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Sep 28, 2016 9:48 pm    Post subject: Reply with quote

You shouldn't be calling GC functions yourself unless absolutely necessary. And if your application is at the point where it becomes needed, then you need to go back and review your code because you are either doing something extremely wrong, or very poorly. Usually the only time you should ever manually call GC functions are to block it from collecting an object that you want to persist.

You are also causing two garbage collections to happen in a row (by calling GetTotalMemory another GC is done) and you do not use the return. That is just useless overhead.

Something else to consider is that Timers are not guaranteed to be threaded / threadsafe. Meaning your GC timer can land up locking up the UI thread in some conditions.

Overall things like this should not be needed. If you are having memory issues with your apps then you need to review your code and do things better.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites