I'm working on a project targeting Z8 and thought I'd share a few tips
on saving precious "readable memory".
#1: Avoid indexed text if possible. I've found through testing that
indexed text consumes about 10K of readable memory. The cost of using
indexed text is fixed, but 10K is considerable (about 1/6 of the total
readable memory). Things I've found that use indexed text include:
- Finding the number of characters in text
- Regular expressions
#2: I'm not sure where I saw it, but declaring constants like this:
The minimum screen width is a number that varies. The minimum screen
width is 80.
is really wasteful. Each "number that varies" or "text that varies" uses
4 bytes of readable memory. Instead, it's much more efficient to declare
a constant like so:
To decide what number is the minimum screen width:
decide on 80.
And similarly, if you're not going to change the numbers in a table
(i.e. it's read only), consider instead doing your lookups with:
To decide what text is message number (message index - a number):
let the decision be ...;
if the message index is 1...
...
otherwise if...
...
otherwise:
...
decide on the decision.
Well... that's all I have. When I first examined my project's readable
memory usage using (on Windows):
inform-631.exe -Ssw auto.inf
I was alarmed to see that I'd used a massive 40K out of 64K just
implementing the introduction and a few game concepts. Given that Inform
requires a minimum of about 20K for any project, I'd used about 20K or
~45% of what's really available to a game. Using the two tips above, I
managed to trim this down to just 27K or ~16% of what's available.
Are there any other tips for saving readable memory I should know about?
> Are there any other tips for saving readable memory I should know about?
The tips you provided look good to me, though I'm not an expert. I guess
my main tip would be, if you're concerned about memory usage and want to
target the Z-machine, consider writing your game in Inform 6! My
impression (again, I'm not an expert) is that I7 imposes a certain
amount of overhead, and that in consequence you'll be able to write a
larger game in I6.
If you're curious how to economize on readable memory in an I6 game,
there are some tips here:
http://www.inform-fiction.org/manual/html/s45.html. This is section 45
of the DM4. Using any of these techniques in I7 would probably be
awkward, if not impossible.
--JA
True.
> #2: I'm not sure where I saw it, but declaring constants like this:
>
> The minimum screen width is a number that varies. The minimum screen
> width is 80.
>
> is really wasteful. Each "number that varies" or "text that varies" uses
> 4 bytes of readable memory.
I'm going to go out on a limb and say that four bytes (out of 64k) is
not *really* wasteful. Your alternatives save RAM at the expense of
execution speed, and that is also a critical resource for complex
games.
If you are up against the 64k boundary, find a relation or property
that spans a lot of objects, which you can restrict to a smaller set
(a limited "kind of thing", rather than all "things"). That will save
you a lot more than four bytes.
--Z
--
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
Really? Wouldn't it be better all-around to do..
To decide what number is the minimum screen width: (- 80 -).
..which would just hard-code the constant in the generated I6? Or is
yours being inlined by an optimizer?
-R
It would! Thanks for the tip!
Or ZIL!
Cloak of Darkness in I7: 179 KB Z5
Cloak of Darkness in I6: 72 KB Z5
Cloak of Darkness in ZIL: 5 KB Z5
vw
I've thought about using ZAPF before, but it's "Inform" mode is still
really quite different. If only it accepted the same syntax.
The syntax will always have to be fairly different, because Inform
itself is not a very complete assembler: it has no way to provide
default parameter values, define tables in static memory or routines
in dynamic memory, set the size or contents of the "extra data" in
dictionary words, etc., and its object directives are higher level
than ZAPF is designed for.
But now is probably the best time to make drastic changes to Inform
mode, before anyone starts seriously using it, and ZAPF's parser is
due to be rewritten after the 0.3 release. I could see adding support
for enough I6-ish syntax that there would at least be a common subset
of code that compiles under Inform and ZAPF.
vw
>
>Or ZIL!
>
>Cloak of Darkness in I7: 179 KB Z5
>Cloak of Darkness in I6: 72 KB Z5
>Cloak of Darkness in ZIL: 5 KB Z5
>
>vw
Forgive if this sounds terribly ignorant, but I didn't think Infocom's compiler
for ZIL was released. Is it? Or are we talking about something else? I'd be
interested in trying it out, if it did.
-Pete
Heh, never mind. I read further in the thread and used Google. ZAPF looks
very interesting. Does anyone know how stable it is for .Z5?
"Snacky Pete" <snack...@hotmail.com> wrote in message
news:41tjs51u9382r9h52...@4ax.com...
>If you think ZAPF is interesting, check out ZILF. ZILF is a modern ZIL
>compiler which compiles to assembly code which is then passed to ZAPF to
>make the Z-machine story file.
>
Can't wait! Unfortinately, there's nothing on its Sourceforge project page
yet. Is it located elsewhere?
The SourceForge page will be updated soon for the upcoming 0.3
release. For now, you can download the current version from my site:
http://hansprestige.com/zil/zilf-0.2.zip
vw