• 0

VB.Net resources


Question

Hi Guys and Gals,

I made a little program in VB.Net that started and stopped my Apache2 and MySQL services on my PC, if I look at the resources of my little program which is about 20 lines of code its using about 20,000k which is about the same as IE6 when its running.

Do all VB.Net programs have high resources ?

Is their a way to make programs use less resources or is it the .Net framework that ups the resources of running programs ?

Any help much appreciated.

Kind Regards

Link to comment
Share on other sites

22 answers to this question

Recommended Posts

  • 0

Initially, yes. The environment does a virtual allocation for your app, which reserves a specific amount of memory for your app. Over time, usage *should* decrease.

Link to comment
Share on other sites

  • 0
Over time, usage *should* decrease.

Thanks Weenur,

You say over time usage should decrease, how does that work ?

Does the framework know what programs I run on a regular basis, so that the more I use a .Net app the lower the resources it uses.

Please tell me if I'm thinking along the right lines ?

Kind Regards

Link to comment
Share on other sites

  • 0

Hi kjordan2001,

The only thing I don't understand and what I'm trying to get my head around is why would my little 20 line application uses the same amount of resources as IE6 which is a considerably bigger program.

Kind Regards

Link to comment
Share on other sites

  • 0

because you probably have quite a bit of free ram.

If you don't have much free ram, the program will take up less resources, if you have more, it'll take up more. It's just the way it works.

Link to comment
Share on other sites

  • 0
Hi kjordan2001,

The only thing I don't understand and what I'm trying to get my head around is why would my little 20 line application uses the same amount of resources as IE6 which is a considerably bigger program.

Kind Regards

The CLR performs an allocation regarless of actual memory required. In reality, your app is probably only using maybe 1 MB. The memory allocated is known as the managed heap. It is faster to allocate new memory from the managed heap than it is from unmanaged space. That's why the CLR does what it does. This is the price of managed applications.

Link to comment
Share on other sites

  • 0
The CLR performs an allocation regarless of actual memory required. In reality, your app is probably only using maybe 1 MB. The memory allocated is known as the managed heap. It is faster to allocate new memory from the managed heap than it is from unmanaged space. That's why the CLR does what it does. This is the price of managed applications.

THANK YOU!

It's about goddamn time I've heard a real explanation for that. I've always known that the CLR over-allocates, but not the reason for that. I don't see why the Microsofties are at such a loss to explain the behaviour; generally they either don't answer, pretend it doesn't happen or say that programmers "are allocating too many objects now that they don't have to clean them up themselves." *cough*

Link to comment
Share on other sites

  • 0
Hmm is there anyway of forcibly reducing this allocation? From the developers side that is?

There is a way to, but, honestly, I use it, and I plan on removing it from my app. It's not worth it. The program uses the same amount of memory no matter what.

Weenur.....definitely one of the best in this forum. Good explanation man.

Link to comment
Share on other sites

  • 0

? ?Public Sub FreeMemory()
 ? ? ? ?System.GC.Collect()
 ? ? ? ?System.GC.WaitForPendingFinalizers()
 ? ? ? ?SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
 ? ?End Sub

T;)t should work ;)

Link to comment
Share on other sites

  • 0

Yeah the SetProcessWorkingSetSize API will work... however... i'ts said at times to not use it, not sure why, i initially used this when i use the 1.0 framework, it does decrease the usage, but really the Task Manager, doesn't actually show how much memory is physically consumed by the actual process, as mentioned, it's forward allocated, and the more apps you have opened, and memory is decreasing your applications will generally decrease as well... It's all mental thing, even if you use this API call, you won't have a performance increase, but have ther task manager displaying the real amount of memory actually being used by your application.

Link to comment
Share on other sites

  • 0

Yeah, its a psycological (how is that spelt?) thing... If you give your app to a friend and he sees it using 50MB of memory, he simply won't use it.. let alone a person who does not even know you... So I actually had to include that in my app so people would use it... And explaining that memory would be freed when the system needed it was not enough.. :s

Link to comment
Share on other sites

  • 0
It says SetProcessWorkingSetSize is not declared. What do i declare it as?

It's not just calling that, you have to import a DLL i remember.

Link to comment
Share on other sites

  • 0

ummmm i read that you're new to VB.NET, perhaps you should learn more about the language etc.. first before attempting, like i had to use this because i did mine for an assignment other than that, i wouldn't use it... so just take the peoples words for it, it's not really necessary...

Link to comment
Share on other sites

  • 0

Yeah actually i am trying to learn the language. What exactly is the code? I dont really need it but its nice to know

Link to comment
Share on other sites

  • 0

using System;
using System.Runtime.InteropServices;

	public class Win32APIs
	{
  [DllImport("kernel32.dll")]
  public extern static bool SetWorkingProcessSetSize( IntPtr hProcess, int min, int max );
	}

It shouldn't be too different for VB.NET

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.