To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1845
1844  |  1846
Subject: 
Re: Memory question
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Tue, 13 Dec 2005 19:57:31 GMT
Viewed: 
6083 times
  
In lugnet.robotics.rcx.nqc, Steve Lane wrote:

Say I had a program that has a very large block of start-up/calibration
code that is run once at the top of the program. Does it make any
difference if I keep it in the "Main()" task, or put it in a function?

   Most functions in NQC are in-line functions, so in a sense they probably
*are* in main(). One thing I do is place all my initalization code (as much as
possible) into inline functions. That way, when the compilier runs through, it
can allocate variable space as best it can, reusing variables in different
functions as they fall in and out of scope. Saves me from running out of
variables in some cases.

   Another thing you can do is have a seperate program do all your
initalization, and then have the main program run "pre-initalized" as it were
(thanks SMART). The standard firmware doesn't zero-out global variables between
runs, so *as long as the variable lists correspond*, the global variables
initalized by one program will be accessible to another:

===== program 1 =====

int x;
task main()
{
  x=3;
}

===== program 2 =====

int x;
task main()
{
   x=5;
}

===== program 3 =====

int x;
task main()
{
   while(x != 0)
   {
      PlayTone(440,20);
      Wait(30);
      x--;
   }
}

Try running program 1 followed by program 3, and then program 2 followed by
program 3. This can help with complex calibration issues, save runtime, and make
better use of variables in some cases.

--
Brian Davis



Message has 1 Reply:
  Re: Memory question
 
(...) So what your saying is I should split my program into more functions not less, so that the local ints are destroyed and available for re-use. That's a great idea, it's the complete opposite of my question but fulfills my goal perfectly :-). (...) (19 years ago, 13-Dec-05, to lugnet.robotics.rcx.nqc)

Message is in Reply To:
  Memory question
 
Say I had a program that has a very large block of start-up/calibration code that is run once at the top of the program. Does it make any difference if I keep it in the "Main()" task, or put it in a function? I mean from the point of stack space (...) (19 years ago, 13-Dec-05, to lugnet.robotics.rcx.nqc)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR