|
123 | 123 | <div class="headertitle"><div class="title">CHAIN Keyword </div></div> |
124 | 124 | </div><!--header--> |
125 | 125 | <div class="contents"> |
126 | | -<div class="textblock"><div class="fragment"><div class="line">CHAIN string-expression[,boolean-expression]</div> |
127 | | -</div><!-- fragment --><p>Starts a new BASIC program, pausing the current program until the new one finishes. <br /> |
128 | | - The string expression must evaluate to the <b>filename</b> of a program accessible from the filesystem.</p> |
| 126 | +<div class="textblock"><div class="fragment"><div class="line">CHAIN string-expression[,boolean-expression] [MEMORY SMALL|MEDIUM|LARGE|HUGE]</div> |
| 127 | +</div><!-- fragment --><p>Starts a new BASIC program, pausing the current program until the new one finishes. The string expression must evaluate to the <b>filename</b> of a program accessible from the filesystem.</p> |
129 | 128 | <ul> |
130 | 129 | <li>Any variables marked as <a class="el" href="GLOBAL.html">GLOBAL</a> will be shared with the child program.</li> |
131 | | -<li>When the chained program terminates, control returns to the line immediately following the <span class="tt">CHAIN</span> statement in the calling program. <br /> |
132 | | -</li> |
| 130 | +<li>When the chained program terminates, control returns to the line immediately following the <span class="tt">CHAIN</span> statement in the calling program.</li> |
133 | 131 | <li>Variables not marked as global are not visible to the chained program.</li> |
134 | 132 | <li>If the optional boolean expression is included and evaluates to true, the program will be launched as a task in the background and the caller will resume immediately.</li> |
| 133 | +<li>The optional <span class="tt">MEMORY</span> clause selects the memory model used by the new program.</li> |
135 | 134 | </ul> |
| 135 | +<hr /> |
| 136 | +<h5 class="doxsection"><a class="anchor" id="memory-models"></a> |
| 137 | +Memory Models</h5> |
| 138 | +<p>The <span class="tt">MEMORY</span> option controls the size of the allocator used by the child program:</p> |
| 139 | +<ul> |
| 140 | +<li><span class="tt">SMALL</span> — up to 32 MiB per allocation</li> |
| 141 | +<li><span class="tt">MEDIUM</span> — up to 64 MiB per allocation <em>(default)</em></li> |
| 142 | +<li><span class="tt">LARGE</span> — up to 128 MiB per allocation</li> |
| 143 | +<li><span class="tt">HUGE</span> — up to 256 MiB per allocation</li> |
| 144 | +</ul> |
| 145 | +<p>If not specified, the child program uses the <b>same memory model as the caller</b>, or <span class="tt">MEDIUM</span> if no parent model applies.</p> |
| 146 | +<p>If the requested memory model cannot be allocated, the <span class="tt">CHAIN</span> will fail with an out-of-memory error.</p> |
| 147 | +<dl class="section remark"><dt>Remarks</dt><dd>The memory model does not limit the total memory a program may use.It limits the size of any single contiguous allocation (for example, a string or buffer), and programs may use more memory overall but individual allocations cannot exceed the selected model.</dd></dl> |
| 148 | +<hr /> |
136 | 149 | <dl class="section remark"><dt>Remarks</dt><dd><span class="tt">CHAIN</span> resolves relative paths from the <b>current working directory</b>. </dd> |
137 | 150 | <dd> |
138 | 151 | Use absolute paths (e.g. <span class="tt">/programs/login</span>) if you don’t want this to depend on <span class="tt">CHDIR</span>.</dd></dl> |
139 | 152 | <hr /> |
140 | | -<h5 class="doxsection"><a class="anchor" id="example-7"></a> |
141 | | -Example</h5> |
| 153 | +<h5 class="doxsection"><a class="anchor" id="examples-150"></a> |
| 154 | +Examples</h5> |
142 | 155 | <div class="fragment"><div class="line">PRINT "Before chain"</div> |
143 | 156 | <div class="line">GLOBAL X = 42</div> |
144 | 157 | <div class="line">CHAIN "childprog"</div> |
145 | 158 | <div class="line">PRINT "Back again, X = "; X</div> |
146 | | -</div><!-- fragment --><p>If <span class="tt">childprog</span> uses the global variable <span class="tt">X</span>, it will see the value <span class="tt">42</span>. <br /> |
147 | | - After <span class="tt">childprog</span> ends, execution resumes.</p> |
148 | | -<hr /> |
| 159 | +</div><!-- fragment --><div class="fragment"><div class="line">CHAIN "worker", TRUE MEMORY SMALL</div> |
| 160 | +</div><!-- fragment --><div class="fragment"><div class="line">CHAIN "bigdata" MEMORY LARGE</div> |
| 161 | +</div><!-- fragment --><div class="fragment"><div class="line">CHAIN "analysis" MEMORY HUGE</div> |
| 162 | +</div><!-- fragment --><hr /> |
149 | 163 | <h5 class="doxsection"><a class="anchor" id="notes-148"></a> |
150 | 164 | Notes</h5> |
151 | 165 | <ul> |
152 | 166 | <li>Chained programs run in a <b>new interpreter instance</b> within a new process. The parent remains suspended until the child exits, unless the child is launched as a background task.</li> |
153 | | -<li>A chained program may itself issue <span class="tt">CHAIN</span> statements, nesting as required. <br /> |
154 | | -</li> |
| 167 | +<li>A chained program may itself issue <span class="tt">CHAIN</span> statements, nesting as required.</li> |
155 | 168 | <li>If the file specified in <span class="tt">string-expression</span> cannot be found, an error is raised (and can be caught with <span class="tt">ON ERROR</span>).</li> |
| 169 | +<li>The memory model determines the <b>maximum size of any single allocation</b>, not the total memory usage of the program.</li> |
156 | 170 | <li>Unlike BBC BASIC, Retro Rocket’s <span class="tt">CHAIN</span> does <b>not</b> discard the caller - the parent program continues afterwards.</li> |
157 | 171 | </ul> |
| 172 | +<hr /> |
158 | 173 | <p><b>See also:</b> <a class="el" href="GLOBAL.html">GLOBAL</a>, <a class="el" href="LIBRARY.html">LIBRARY</a> </p> |
159 | 174 | </div></div><!-- contents --> |
160 | 175 | </div><!-- PageDoc --> |
|
0 commit comments