Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I7: Z-Machine Readable Memory Saving Tips

5 views
Skip to first unread message

Benjamin Penney

unread,
Apr 15, 2010, 12:22:45 AM4/15/10
to
Hi,

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?

Jim Aikin

unread,
Apr 15, 2010, 1:21:51 AM4/15/10
to
On 4/14/2010 9:22 PM, Benjamin Penney wrote:

> 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


Andrew Plotkin

unread,
Apr 15, 2010, 1:22:46 AM4/15/10
to
Here, Benjamin Penney <benj...@nerdshack.com> wrote:
> Hi,
>
> 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

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..."
*

Ron Newcomb

unread,
Apr 15, 2010, 1:37:59 AM4/15/10
to
> 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.
>

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

Benjamin Penney

unread,
Apr 15, 2010, 7:40:47 AM4/15/10
to

It would! Thanks for the tip!

vaporware

unread,
Apr 15, 2010, 9:17:41 PM4/15/10
to
On Apr 14, 10:21 pm, Jim Aikin <midigur...@gmail.com> wrote:
> On 4/14/2010 9:22 PM, Benjamin Penney wrote:
>
> > 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!

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

Dannii

unread,
Apr 15, 2010, 10:09:15 PM4/15/10
to

I've thought about using ZAPF before, but it's "Inform" mode is still
really quite different. If only it accepted the same syntax.

vaporware

unread,
Apr 15, 2010, 10:33:59 PM4/15/10
to

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

Snacky Pete

unread,
Apr 17, 2010, 1:34:37 PM4/17/10
to
On Thu, 15 Apr 2010 18:17:41 -0700 (PDT), vaporware <jmc...@gmail.com> wrote:

>
>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

Snacky Pete

unread,
Apr 17, 2010, 1:48:09 PM4/17/10
to

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?

Jayson Smith

unread,
Apr 17, 2010, 1:54:16 PM4/17/10
to
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.

"Snacky Pete" <snack...@hotmail.com> wrote in message
news:41tjs51u9382r9h52...@4ax.com...

Snacky Pete

unread,
Apr 17, 2010, 3:49:35 PM4/17/10
to
On Sat, 17 Apr 2010 13:54:16 -0400, "Jayson Smith"
<ihatespamratg...@insightbb.spamsucks.com> wrote:

>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?

vaporware

unread,
Apr 17, 2010, 5:16:14 PM4/17/10
to
On Apr 17, 12:49 pm, Snacky Pete <snackyp...@hotmail.com> wrote:
> On Sat, 17 Apr 2010 13:54:16 -0400, "Jayson Smith"
>
> <ihatespamratguynospample...@insightbb.spamsucks.com> wrote:
> >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

0 new messages