1
0
mirror of synced 2026-01-24 19:51:16 +00:00
2021-01-22 15:26:25 -08:00

3 lines
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>22-RESOURCE-MANAGEMENT</title><link href="navigation.css" rel="stylesheet" type="text/css"/><link href="document.css" rel="stylesheet" type="text/css"/></head><body><p class="top_nav"><a href="part24.htm">&lt; Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part26.htm">Next &gt;</a></p><h1 style="padding-top: 3pt;padding-left: 35pt;text-indent: 0pt;text-align: left;"><a name="bookmark24">22. RESOURCE MANAGEMENT</a></h1><p style="padding-left: 35pt;text-indent: 0pt;line-height: 6pt;text-align: left;"><span><img width="640" height="8" alt="image" src="Image_153.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Naming Variables and Records </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">You will find times when one environment simultaneously hosts a number of different programs. Running a demo of several programs, or reloading the entire Medley</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">environment from floppies when it contains several different programs, are two</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">examples that could, if you arent careful, provide a few problems. Here are a few tips on how to prevent problems:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -10pt;line-height: 107%;text-align: justify;">• If you change the value of a system variable, <span class="s3">MENUHELDWAIT </span>for example, or connect to a directory other than <span class="s3">{DSK}&lt;LISPFILES&gt; </span>, write a function to reset the variable or directory to its original value. Run this function when you are finished working.</p><p style="padding-left: 119pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">This is especially important if you change any of the system menus.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -10pt;text-align: left;">• Do not redefine Medley functions or CLISP words. Remember, if you reset an atoms value or function definition at the top level (in the Executive Window), the message (<i>Some.Crucial.Function.Or.Variable </i><span class="s3">redefined) </span>, appears. If this is not what you wanted, type <span class="s9">UNDO </span>immediately!</p><p style="padding-top: 10pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">If, however, you reset the value or function definition of an atom inside your program, a warning message will not be printed.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -10pt;text-align: left;">• Make the atom names in your programs as unique as possible. To do this without filling your program with unreadable names that noone, including you, can</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">remember, prefix your variable names with the initials of your program. Even then, check to see that they are not already being used with the function <span class="s3">BOUNDP </span>. For</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">example, type:</p><p class="s3" style="padding-top: 7pt;padding-left: 179pt;text-indent: 0pt;text-align: left;">(BOUNDP BackgroundMenu)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">This atom is bound to the menu that appears when you press the leff mouse button</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">when the mouse cursor is not in any window. <span class="s3">BOUND</span>P returns <span class="s3">T</span>. <span class="s3">BOUNDP </span>returns <span class="s3">NIL</span></p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">if its argument does not currently have a value.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 108pt;text-indent: 0pt;text-align: left;">• Make your function names as unique as possible. Once again, prefixing function</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">names with the initials of your program can be helpful in making them unique, but even so, check to see that they are not already being used. <span class="s3">GETD </span>is the Interlisp-D function that returns the function definition of an atom, if it has one. If an atom has no function definition, <span class="s3">GETD </span>returns <span class="s3">NIL</span>. For example, type:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(GETD CAR)</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">A non-<span class="s3">NIL </span>value is returned. The atom <span class="s3">CAR </span>already has a function definition.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -11pt;line-height: 107%;text-align: left;">• Use complete record field names in record <span class="s3">FETCH</span>es and <span class="s3">REPLACE </span>s when your code is not compiled. A complete record field name is a list consisting of the record</p><p style="padding-left: 119pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">declaration name and the field name. Consider the following example:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(REC0RD NAME (FIRST LAST))</p><p class="s3" style="padding-left: 143pt;text-indent: 0pt;line-height: 88%;text-align: left;">(SETQ MyName (create Name FIRST <span class="s2"></span>John LAST <span class="s2"></span>Smith)) (FETCH (NAME FIRST) OF MyName)</p><p style="padding-top: 9pt;padding-left: 119pt;text-indent: -11pt;text-align: left;">• Avoid reusing names that are field names of Lisp system records. A few examples of system records follow. Do not reuse these names.</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;line-height: 88%;text-align: left;">(RECORD REGION (LEFT BOTTOM WIDTH HEIGHT)) (RECORD POSITION (XCOORD YCOORD))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 4pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(RECORD IMAGEOBJ (- BITMAP -<span class="p">)))</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -11pt;text-align: left;">• When you select a record name and field names for a new record, check to see whether those names have already been used.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: 0pt;line-height: 107%;text-align: left;">Call the function <span class="s3">RECLOOK</span>, with your record name as an argument, in the Executive Window (see Figure 22-1). If your record name is already a record, the record</p><p style="padding-left: 119pt;text-indent: 0pt;line-height: 12pt;text-align: left;">definition will be returned; otherwise the function will return <span class="s3">NIL</span>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 191pt;text-indent: 0pt;text-align: left;"><span><img width="329" height="142" alt="image" src="Image_154.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 230pt;text-indent: 0pt;text-align: left;">Figure 22-1. Response to <span class="s3">RECLOCK</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;line-height: 106%;text-align: left;">Call the function <span class="s3">FIELDLOOK </span>with your new field name in the Executive Window (see Figure 22-2). If your field name is already a field name in another record, the record definition will be returned; otherwise the function will return <span class="s3">NIL</span>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 188pt;text-indent: 0pt;text-align: left;"><span><img width="329" height="142" alt="image" src="Image_155.gif"/></span></p><p style="padding-top: 9pt;padding-left: 226pt;text-indent: 0pt;text-align: left;">Figure 22-2. Response to <span class="s3">FIELDLOOK</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Some Space and Time Considerations </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">In order for your program to run at maximum speed, you must efficiently use the space available on the system. The following section points out areas that you may not know are wasting valuable space, and tips on how to prevent this waste.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Often programs are written so that new data structures are created each time the</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">program is run. This is wasteful. Write your programs so that they only create new variables and other data structures conditionally. If a structure has already been</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">created, use it instead of creating a new one.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Some time and space can be saved by changing your <span class="s3">RECORD </span>and <span class="s3">TYPERECORD</span></p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: justify;">declarations to <span class="s3">DATATYPE </span>. <span class="s3">DATATYPE </span>is used the same way as the functions <span class="s3">RECORD </span>and <span class="s3">TYPERECORD</span>. In addition, the same <span class="s3">FETCH </span>and <span class="s3">REPLACE </span>commands can be used with the data structure <span class="s3">DATATYPE </span>creates. The difference is that the data structure</p><p class="s3" style="padding-left: 107pt;text-indent: 0pt;text-align: left;">DATATYPE <span class="p">creates cannot be treated as a list the way </span>RECORD <span class="p">s and </span>TYPERECORD<span class="p">s can.</span></p><p class="s6" style="padding-top: 3pt;text-indent: 0pt;text-align: right;">22. RESOURCE MANAGEMENT</p><p style="padding-left: 35pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="665" height="1" alt="image" src="Image_156.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 71pt;text-indent: 0pt;text-align: left;">Global Variables</h3><p style="padding-top: 8pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Once defined, global variables remain until Lisp is reloaded. Avoid using global</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">variables if at all possible! One specific problem arises when programs use the function</p><p class="s3" style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">GENSYM<span class="p">. In program development, many atoms are created that may no longer be useful. Hints:</span></p><p style="padding-top: 6pt;padding-left: 108pt;text-indent: 0pt;text-align: left;">• Use</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(DELDEF <span class="s4">atomname </span>PROP)</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">to delete property lists, and</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(DELDEF <span class="s4">atomname </span>VARS)</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">to have the atom act like it is not defined.</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">These not only remove the definition from memory, but also change the appropriate <span class="s3">fileCOMS </span>that the deleted object was associated with so that the file package will not attempt to save the object (function, variable, record definition, and so forth) the next time the file is made. J ust doing something like</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(SETQ (<span class="s4">arg atomname</span>) NOBIND)</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;line-height: 107%;text-align: left;">looks like it will have the same effect as the second <span class="s3">DELDEF </span>above, but the <span class="s3">SETQ </span>does not update the file package.</p><p style="padding-top: 6pt;padding-left: 119pt;text-indent: -11pt;line-height: 107%;text-align: left;">• If you are generating atom names with <span class="s3">GENSYM </span>, try to keep a list of the atom names that are no longer needed. Reuse these atom names, before generating new ones.</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">There is a (fairly large) maximum to the number of atoms you can have, but things slow down considerably when you create lots of atoms.</p><p style="padding-top: 6pt;padding-left: 108pt;text-indent: 0pt;text-align: left;">• When possible, use a data structure such as a list or an array, instead of many</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">individual atoms. Such a structure has only one pointer to it. Once this pointer is</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">removed, the whole structure will be garbage-collected and space will be reclaimed.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 71pt;text-indent: 0pt;text-align: left;">Circular Lists</h3><p style="padding-top: 8pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">If your program is creating circular lists, a lot of space may be wasted. (Many</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">crosslinked data structures end up having circularities.) Hints when using circular lists:</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: -11pt;text-align: left;">• Write a function to remove pointers that make lists circular when you are through with the circular list.</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: -10pt;text-align: left;">• If you are working with circular lists of windows, bind your main window to a unique global variable. Write window creation conditionally so that if the binding of that</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">variable is already a window, use it, and only create a new window if that variable is unbound or <span class="s3">NIL</span>.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">Here is an example that illustrates the problem. When several auxilIary windows are built, pointers to these windows are usually kept on the main windows property list.</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">Each auxilIary window also typically keeps a pointer to the main window on its</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">property list If the top level function creates windows rather than reusing existing ones, there will be many lists of useless windows cluttering the work space. Or, if such a main window is closed and will not be used again, you will have to break the links by deleting the relevant properties from both the main window and all of the auxiliary windows</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: justify;">first. This is usually done by putting a special <span class="s3">CLOSEFN </span>on the main window and all of its auxiliary windows.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-top: 4pt;padding-left: 71pt;text-indent: 0pt;text-align: left;">When You Run Out of Space</h3><p style="padding-top: 8pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">Typically, if you generato a lot of structure! that wont get garbage collected, you will eventually run out of space. The important part ii being aNe to track down those</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">structures and the code that generates them to become more space efficient.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: justify;">Use the Lisp Library Package <span class="s3">GCHAX.DCOM </span>to track down pointers to data structures. The basic idea is that <span class="s3">GCHAX </span>will return the number of references to a particular data structure.</p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">A special function exists that allows you to get a little extra space so that you can try to save your work when you get toward the edge (usually noted by a message indicating</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">that you should save your work and load a new Medley environment). The <span class="s3">GAINSPACE</span></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">function allows you to delete non-essential data structures. To use it, type:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(GAINSPACE)</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">into the Executive Window. Answer <span class="s3">N </span>to all questions except the followi ng.</p><p style="padding-top: 7pt;padding-left: 108pt;text-indent: 0pt;text-align: left;">• Delete edit history</p><p style="padding-top: 7pt;padding-left: 108pt;text-indent: 0pt;text-align: left;">• Delete history list.</p><p style="padding-top: 7pt;padding-left: 108pt;text-indent: 0pt;text-align: left;">• Delete values of old variables.</p><p style="padding-top: 7pt;padding-left: 108pt;text-indent: 0pt;text-align: left;">• Delete your <span class="s3">MASTERSCOPE </span>database</p><p style="padding-top: 7pt;padding-left: 108pt;text-indent: 0pt;text-align: left;">• Delete information for undoing your greeting.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Save your work and reload Lisp as soon as possible.</p><p class="nav">&nbsp;&nbsp;</p><p class="nav">&nbsp;</p><p class="nav"><a href="part24.htm">&lt; Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part26.htm">Next &gt;</a></p><p class="nav">&nbsp;&nbsp;</p></body></html>