Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 12-28-2006, 02:25 AM   #1 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default .Net memory usage

Ok, I know that when you view the memory usage of a .net program, a bulk of the memory shown is the framework. However, I am curious if there is a way to reduce this? Currently, I have a program that finds the handle of window and then depending on if my mouse is near the side of my screen or if the window is active, display the window and if not, hides it. There is no way that this takes between 11 Mb and 13 Mb, but no matter what I try, I cant get this any smaller. So, just wondering if there is anything I should try or do to get this to be smaller (or appear to be smaller).

One thing I am currently doing is hiding my form as soon as the program starts cause it isnt needed. The only thing I need is a notify icon with a context menu to exit. So is there a way to get a program to run without using window forms and still have the notify icon?

Anyways, thanks

Edit: Well I found -->this<-- (its a google cache cause the page couldnt be found). This drops me down to around 2 Mb, which is still kind of big for what im doing but its better than before. Still if anyone knows of anything else I could do, it would be appreciated

Last edited by mordero; 12-28-2006 at 03:59 AM.
mordero is offline   Reply With Quote
Old 12-28-2006, 11:08 AM   #2 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Location: In your mom
Age: 27
Posts: 4,763
Default

Quote:
Originally Posted by mordero View Post
Ok, I know that when you view the memory usage of a .net program, a bulk of the memory shown is the framework. However, I am curious if there is a way to reduce this? Currently, I have a program that finds the handle of window and then depending on if my mouse is near the side of my screen or if the window is active, display the window and if not, hides it. There is no way that this takes between 11 Mb and 13 Mb, but no matter what I try, I cant get this any smaller. So, just wondering if there is anything I should try or do to get this to be smaller (or appear to be smaller).

One thing I am currently doing is hiding my form as soon as the program starts cause it isnt needed. The only thing I need is a notify icon with a context menu to exit. So is there a way to get a program to run without using window forms and still have the notify icon?

Anyways, thanks

Edit: Well I found -->this<-- (its a google cache cause the page couldnt be found). This drops me down to around 2 Mb, which is still kind of big for what im doing but its better than before. Still if anyone knows of anything else I could do, it would be appreciated
Welcome to the memory restrictions of using a framework. If you need it smaller, you will need to write it in C++ or other equivilant languages.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 12-28-2006, 01:40 PM   #3 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

oh well guess its good experience learning new languages...
mordero is offline   Reply With Quote
Old 12-28-2006, 06:44 PM   #4 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Location: In your mom
Age: 27
Posts: 4,763
Default

Smallest I could get with was this



code was

Code:
namespace TestingMemorySize
{
	class Program
	{
		[System.Runtime.InteropServices.DllImport("kernel32.dll")]
		private extern static void SetProcessWorkingSetSize(System.IntPtr handle, int min, int max);

		static void Main(string[] args)
		{
			System.GC.Collect();
			System.GC.WaitForPendingFinalizers();
			SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);

			for( int i = 0; i < int.MaxValue; )
				i++;
		}
	}
}
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 12-29-2006, 03:20 PM   #5 (permalink)
Forum Expert
 
TheOutkastDev's Avatar
 
Join Date: Sep 2002
Location: Houston, Texas
Age: 21
Posts: 3,933
Default

I've got a snippet of code somewhere that'll accurately give you the memory usage of your program.
TheOutkastDev is offline   Reply With Quote
Old 12-29-2006, 04:46 PM   #6 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

oh that would be nice too, thanks!
mordero is offline   Reply With Quote
Old 12-29-2006, 07:15 PM   #7 (permalink)
Forum Expert
 
TheOutkastDev's Avatar
 
Join Date: Sep 2002
Location: Houston, Texas
Age: 21
Posts: 3,933
Default

this is from a program I used a little while back

Code:
        private void menuButtonItem5_Activate( object sender, EventArgs e )
        {
            long mem = GC.GetTotalMemory( false );

            string usage = FormatSize( mem );

            this.ActiveWindow.WriteLine( Color.Purple, "*** Current memory usage: {0} ***", usage );
        }

        public static string FormatSize( long size )
        {
            if ( size < 0x400 )
            {
                return string.Format( "{0:#,##0} B", size );
            }
            if ( size < 0x100000 )
            {
                return string.Format( "{0:#,###.0} KB", ( (double)size ) / 1024 );
            }
            return string.Format( "{0:#,###.0} MB", ( (double)size ) / 1048576 );
        }
TheOutkastDev is offline   Reply With Quote
Old 12-29-2006, 08:31 PM   #8 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

thank you
mordero is offline   Reply With Quote
Old 12-30-2006, 02:37 PM   #9 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

it is not good to call GC explicitly in such a case.
let .net do its job on its own.
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
noobie is offline   Reply With Quote
Old 12-30-2006, 10:18 PM   #10 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

Well, seeings as this is just for me, then i see nothing wrong with it. Also, Im only calling it once the program is done doing anything important which is only right after it loads and when it needs to refind the handle of the program.
mordero is offline   Reply With Quote
Old 12-31-2006, 09:04 PM   #11 (permalink)
Forum Expert
 
Join Date: Oct 2002
Posts: 1,125
Default

Quote:
Originally Posted by noobie View Post
it is not good to call GC explicitly in such a case.
let .net do its job on its own.
The purpose of Jeff's exercise was to write a program with C# that used minimal system resources. This explains the call to have the GC free memory during initialization.

I agree that in most scenarios you should let .NET handle all of that stuff - that's what it has been designed to do.
Aenima is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5