![]() | Chapter 19: Advanced Text | ![]() ![]() |
19.2. Memory limitations with indexed text |
Because Inform helps us to pretend that dynamic text is as easy to handle as numbers, we can often forget all about the difference between text and indexed text (until we get to creating variables, properties and table columns, anyway). But it's best to be aware that this really is a pretence. The following warnings are rather like the tiny print about side-effects on medicine bottles: that is, we mostly ignore them, and if the drugs should kill us, well, at least we have the consolation of knowing we were warned.
Inform creates "story files" for very small virtual computers (capable of running on phones, for instance) where memory is tight. If we create a number variable and keep on adding 1 to it, the value simply gets bigger. But if we make some text and keep on adding a letter "x" to it, the text takes up more and more space, growing into longer and longer runs of "x"s until there is no more space to hold it. There are basically three limitations on indexed text:
(1) An amount of memory has to be set aside for indexed text (and other flexible-sized data), and Inform guesses the amount needed. The amount can be increased with a use option, like so:
Use dynamic memory allocation of at least 16384.
Inform raises its estimate of the amount needed to ensure that this amount is always at least its own guess, and also at least any amount declared like this. (And then it rounds up to the nearest power of 2, as it happens.) The default value of "dynamic memory allocation" is 8192.
Glulx story files have the advantage here that, if they find themselves running on version 3.1.0 or later of the Glulx machine, they can use Glulx's new memory allocation features to grow their own memories as necessary, so that there are no hard limits at all.
(2) When text is changed into indexed text, there may a maximum length it cannot exceed. The maximum is normally 1000 characters, which ought to be plenty, but can be raised by sentences such as:
Use maximum indexed text length of at least 2000.
What happens if this is broken, that is, if we try to use text overrunning this length? The Z-machine may simply crash, so if there is any chance that any single indexed text may grow unpredictably large, Glulx should always be used. On Glulx, overrunning text is truncated safely, except that under Glulx 3.1.0 or better the story file will try to use dynamic memory allocation to expand the limit as needed to avoid truncation. (Testing shows that text is slow to manipulate once it grows beyond about 20,000 characters in length, but this is not really surprising.)
(3) Under the Z-machine, indexed text may only contain characters from the so-called "ZSCII" character set - standard numbers, letters, punctuation marks and the commonest West European accented letters. Anything more exotic is likely to be flattened into a question mark "?". Under Glulx, any character can be used.
All of this makes the Z-machine sound very inferior, for indexed text purposes. But note that Z can handle all of the examples in this chapter perfectly happily.
Previous | Contents | Next |