Next -> Making Choices
A second use of Server Side Includes is to return values that cannot be determined when you write the page. Because the Simple Scripting Architecture gives you full access to the internals of the Newton Operating System, you can do any number of awesome things. In this chapter, I'll walk through a script that can return the free heap value. You can follow the RAM status of your server as well as show off to those guys with 128M of RAM and buggy servers that you can run a good ship in under 300K of RAM!
We'll walk through this simpler example first and then in later chapters, we'll do some other stuff with the Newton Operating System.
You'll note that for the next couple sections, I'll reference various Newton Programming documents and books. This is to get you familiar with looking things up in these resources if you're not already. I have provided a link to them for you to download them to your hard drive for your personal reference.
Before we write, we need to assemble the requisite Newtonscript commands to do what we need. In the Newton Programmer's Reference, we find that all you have to do to see the heap value is invoke the Stats()1 method. They suggest doing a Garbage Collection with GC()2 before polling the heap value to ensure that all the cobwebs are blown out of memory before trying to assay how much is free.
I can tell you that Stats() returns a number but since Newotnscript is good at coercing values depending on what you are doing with them, we'll just treat it like it was a string in our script.
Form here on out, I am going to give you the Newtonscript code at once. The narrative will be in the //comment lines. If there are concepts that we just can't deal with in the comments, we'll get to them at the end of the script.
|
Name: Heap Check |
SSI: HEAPSHOW |
|
//First, set up our local variable
|
|
The Heap, of course, will change all the time. You can also use this kind of script to just pull values out of the operating system or the Owner information or whatever else. For instance, this script will return the Fax number of the current Owner of your Newton. Since I didn't include a Fax SSI, this might come in handy.
|
Name: My Fax |
SSI: MYFAX |
|
//First, set up our local variable
|
|
1.
NPR: 23-106
2. NPR: 23-105
3. NPR: 16-107
4. NPR: 16-102