RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

.Net memory usage

mordero

Knight
.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 :)
 

Jeff

Lord
mordero;625968 said:
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

Lord
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++;
		}
	}
}
 
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 );
        }
 

mordero

Knight
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.
 

Aenima

Wanderer
noobie;627143 said:
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.
 
Top