Precisely Speaking
February 08, 2012, 01:42:21 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: So what's news with you?  Tell us about it in "Getting To Know You"!
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Subroutine or Not  (Read 724 times)
DonQuixote
Rock Star
*****
Posts: 101


To Dream the Impossible Dream...


« on: March 17, 2010, 02:42:22 PM »

When writing a UniBasic program what is the difference of starting the program as a SUBROUTINE or not.
I mean besides the advantage of passing variables to a subroutine.
Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #1 on: March 18, 2010, 08:44:51 AM »

The big difference between a subroutine and a program is that a subroutine runs in the memory space already allocated to the current process. A program, by comparison, has to allocate additional memory space to keep it distinct from anything else going on.  This is the basic underpinnings that allows subroutines to pass and receive parameters so freely.

When making the decision of program vs. subroutine, it's usually a matter of context.  For example, if you're writing something that uses SB+ subroutine calls, you'll need SB+'s common memory and therefore you'll probably want a subroutine.  If the code is to be run from TCL and has no need to connect to other subroutines, then a program is likely the best choice.  If you're writing a SUBR-type field definition, then the decision is made; you'll write a subroutine.

Bottom line, to paraphrase Jiminy Cricket: "Let the context be your guide"! Smiley
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!