State where a scalar lives in the three chapters that describe the pool
Chapter 13's limits table said 4096 array elements "in total", Chapter 16 said an instance's fields come out of the same pool and nothing is reclaimed, and Chapter 14's pool table listed `AKBASIC_MAX_ARRAY_VALUES` with no note about what does and does not draw from it. All three were written when a scalar drew from that pool, and all three now understate what a program may do. Each gains the same two facts in the register it is written in. Chapter 13: a scalar does not come out of the 4096, so creating one inside a `GOSUB` or a `FOR` -- the loop counter included -- costs nothing, while a `DIM` inside a scope does and is not given back. Chapter 16: scalars are the exception, and "nothing is reclaimed" is what lets a pointer into a record stay sound after its scope has gone -- which is the reason arrays and structures still spend. Chapter 14: a row for the variable's own storage, and a paragraph on why the value pool is the one budget that needs a second sentence. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -217,7 +217,7 @@ interpreter's error code, which bears no relation to a Commodore error number. P
|
||||
| Line length | 255 |
|
||||
| String length | 255 |
|
||||
| Variables | 128 |
|
||||
| Array elements | 1024 per array, 4096 in total |
|
||||
| Array elements | 1024 per array, 4096 across every array and structure |
|
||||
| Scopes | 32 |
|
||||
| Labels | 64 |
|
||||
| `DATA` items | 512 |
|
||||
@@ -226,3 +226,10 @@ interpreter's error code, which bears no relation to a Commodore error number. P
|
||||
|
||||
Every one is a fixed pool. Nothing in the interpreter calls `malloc`, which is what
|
||||
makes it safe to embed in a game that cannot afford a surprise allocation.
|
||||
|
||||
**A scalar does not come out of the 4096.** It lives in the variable itself, so creating
|
||||
one inside a `GOSUB` or a `FOR` — including the loop counter — costs nothing and can be
|
||||
done for as long as the program runs. An *array* declared inside a scope does come out of
|
||||
it and is not given back: the pool never frees, which is what lets a pointer into a
|
||||
record outlive the scope that declared it. In practice that means `DIM` at the top rather
|
||||
than in a loop, which is where you would have put it anyway.
|
||||
|
||||
Reference in New Issue
Block a user