|
-
Aug 30th, 2003, 07:35 PM
#1
Thread Starter
Frenzied Member
Reduce the memory usage.
Ok, there has been a number of complaints about programs written in the .NET Framework using lots of memory. Here is a way to reduce it using P-Invoke.
You need to import the function SetProcessWorkingSetSize.
VB Code:
<DllImport("kernel32.dll")> _
Public Shared Function SetProcessWorkingSetSize(ByVal handle As IntPtr, _
ByVal min As Int32, _
ByVal max As Int32) _
As Boolean
End Function
Now call the function. You can place this in the constructor.
VB Code:
Dim proc As Process = Process.GetCurrentProcess()
Me.SetProcessWorkingSetSize(proc.Handle, -1, -1)
C# Version
Code:
[DllImport("kernel32.dll")]
public static extern bool SetProcessWorkingSetSize(System.IntPtr handle, int min, int max);
Code:
Process proc = Process.GetCurrentProcess();
SetProcessWorkingSetSize(proc.Handle, -1, -1);
Also, make sure you have a reference to System.Diagnostics and System.Runtime.InteropServices.
-
Aug 31st, 2003, 06:27 AM
#2
Frenzied Member
Why not using MaxWorkingSet of the Process?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 31st, 2003, 09:10 AM
#3
Thread Starter
Frenzied Member
Well, I never thought of that but I'll try.
-
Aug 31st, 2003, 12:03 PM
#4
Sleep mode
Is there a remarkable difference while using this function ?
-
Aug 31st, 2003, 12:59 PM
#5
Thread Starter
Frenzied Member
I tried it and it reduced a program from 15 mb to 4 mb.
-
Aug 31st, 2003, 01:02 PM
#6
Sleep mode
Great . I'll try it too soon . Thanks
-
Aug 31st, 2003, 01:40 PM
#7
Frenzied Member
I doubt that this function be useful in oridinary situations. If you have enugh memory, then why not let the program expand itself? I think the .NET memory manager is smart enough to shrink memory usgae when there is not enugh memory, that's just a guess though.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 31st, 2003, 02:05 PM
#8
yay gay
tell that to ur crazy clients when they are used to 10mb progs and they see 30mb ones
\m/  \m/
-
Aug 31st, 2003, 06:06 PM
#9
Originally posted by Lunatic3
I doubt that this function be useful in oridinary situations. If you have enugh memory, then why not let the program expand itself? I think the .NET memory manager is smart enough to shrink memory usgae when there is not enugh memory, that's just a guess though.
I wouldn't call garbage collection "smart"
Last edited by Kasracer; Sep 1st, 2003 at 01:26 AM.
-
Sep 1st, 2003, 12:17 AM
#10
Frenzied Member
Originally posted by kasracer
I would call garbage collection "smart"
yeah
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Sep 1st, 2003, 01:26 AM
#11
Originally posted by Lunatic3
yeah
*wouldn't
typo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|