# [tex-live] No room for a new \write

David Kastrup dak at gnu.org
Fri Mar 16 23:42:29 CET 2007

Reinhard Kotucha <reinhard.kotucha at web.de> writes:

>>>>>> "Philipp" == Philipp Fäh <pfaeh at mysunrise.ch> writes:
>
>   > No room for a new \write. If you get such a message the only
>   > recourse is to redesign your document.  Is there no possibility to
>   > extend the amount of streams? One day...?
>
> A limit of 32 files which can be open at the same time sounds
> ridiculously nowadays.  Yes, TeX (the program) allows you to have 16
> read and 16 write streams open at the same time.  But the plain TeX
> macros (which are used by LaTeX too) are extremely inefficient.
>
> Register allocation is currently stack based.  If you say
> \newwrite\foo, then \foo is is associated with \write0.  If you then
> say \newwrite\bar, \bar is is associated with \write1, and so on.
>
> The stack pointer is increased whenever you say \newwrite but nothing
> useful happens if you say \closeout.
>
> The alternative would be to make file allocation list based.

[...]

> As far as I can see it is even possible to write a macro package which
> works with plain TeX as well as with LaTeX which replaces the stack
> based approach by a list based system.  Old documents will not be
> broken, people will not notice that /new{read,write} calls are
> ignored.

You are assuming that programs will not reopen a stream after closing
it.  That is quite a daring assumption, since TeX programmers _know_
about write streams being a scarce resource.

To make this work, one would basically have to change \newwrite to
assign a unique id, \openout associate that id with a freelist of
actual stream numbers, \write and \read to map through the uniquely
assigned id to the actual stream number, \closeout to back the id into
the freelist.  Unfortunately, we have to deal with non-\immediate
operations, too.

Another possibility is that \openout/\closeout _change_ the given
stream token from a unique invalid to a freelist managed valid number,
on the assumption that only this stream token will ever be used for
accessing the stream.  Probably true in many cases, but not
necessarily all of them.  And again, non-\immediate operations are
troublesome.

So I don't see the easy way out you see.

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum