Sub procedures

Chronis

Member
Joined
Jul 11, 2006
Messages
9
Programming Experience
Beginner
Hey guys,

Just a quick question in relation to sub procedures to the program I'm creating which I'm trying to use as less memory as possible - Do sub procedures work just like local variables in the aspect that all within the sub procedure is destroyed after it is exited and the memory is available again?

I'm thinking of slapping the code together and just not worrying about it, but it may be tedious to other programmers who may need to update it, but I just wanted to make my program as less resource hungry as possible.

Or am I looking into this way too much, and it doesn't make a difference if i slap the code in one block without any sub procedures compared to if i do?

I would of just thought when you built the program, all the sub procedures would have to be initialised and retained in memory, unlike the local variables.
 
there are experts out there who will tell you that using sub procedures uses a tiny bit more memory and then there are those experts that tell you that it sub's dont effect performance one bit

either way you're talking about a fraction of a milisecond

i would suggest using sub's if you're calling the same sections of code from multiple places, this helps with organizing things
 
Cheers

Ah excellent :)

Thanks a bunch. I mean, thinking about it logically you would have to say that sub procedures would HAVE to cause at least a tiny bit of memory resources, but perhaps I'm forgetting these aren't the days of the Hulking Giants where computers took up whole rooms with 8KB of memory so it really isn't going to cost a difference ;)
 
Actually, the way that vb.net subs are compiled is a bit ugly.[FONT=Verdana,Arial,Helvetica,Geneva,Sans-Serif] Mysteriously a vb.net sub has a .maxstack 8 statement at the top whereas c# does not, not sure what MS were thinking there. Although that does not mean the run time evaluation stack is 8, the statement is used only for static analysis by the verifier during the assembly loading phase. If anyone could explain why a vb.net sub has a .maxstack 8 i would be glad to know.[/FONT]
 
vis781 said:
Actually, the way that vb.net subs are compiled is a bit ugly.[FONT=Verdana,Arial,Helvetica,Geneva,Sans-Serif] Mysteriously a vb.net sub has a .maxstack 8 statement at the top whereas c# does not, not sure what MS were thinking there. Although that does not mean the run time evaluation stack is 8, the statement is used only for static analysis by the verifier during the assembly loading phase. If anyone could explain why a vb.net sub has a .maxstack 8 i would be glad to know.[/FONT]

if someone could explain what any of that means, i would be glad to know :p
 
.maxstack # is the maximum stack frame that can be built for that procedure call based on the high level language used (vb.net, c# etc) I was just interested as to why vb.net would have a .maxstack 8 and c# would be practically nothing even though they are supposed to be equivalent high level languages.
 
Chronis said:
Do sub procedures work just like local variables in the aspect that all within the sub procedure is destroyed after it is exited and the memory is available again?
Unless I'm mistaken, I don't believe this question has been addressed.

If the variable declared in the procedure is of a type that implements the IDisposable interface (Pen, SolidBrush, Bitmap, Image, ...) then you should usually call it's Dispose method so that the instance can dispose of it's resources.

As far as the memory being available after the completion of the procedure; this is left up to the Garbage Collector. That's true for sub procedures as well as local variables. There are many articles and discussions on this forum and elsewhere regarding the Garbage Collector.
 
Back
Top