以下操作将耗尽 TeX 的最大内存:
% arara: pdftex
\nonstopmode
\input expl3-generic \relax \ExplSyntaxOn
\int_zero:N \l_tmpa_int
\int_while_do:nn { \l_tmpa_int < 490000 }
{
\cs_new:cn { temp \int_use:N \l_tmpa_int : } { nothing }
\int_show:N \l_tmpa_int
\int_incr:N \l_tmpa_int
}
hi
\bye
给出错误
! TeX capacity exceeded, sorry [number of strings=494671].
在 489008 个定义之后。(我假设剩余的约 5k 个定义来自内核和格式。)
我假设这个数字可以在某个配置文件中找到(对于构建 TeX 的“巫师”),但我如何才能number of strings=
从 TeX 内部动态获取这个数字呢?
sh-3.2$ cat temp-file--8751S9O.tex
hi \bye
sh-3.2$ tex temp-file--8751S9O.tex >/dev/null
sh-3.2$ cat temp-file--8751S9O.log
This is TeX, Version 3.14159265 (TeX Live 2015) (preloaded format=tex 2015.5.24) 26 JUL 2015 09:34
**temp-file--8751S9O.tex
(./temp-file--8751S9O.tex [1] )
Output written on temp-file--8751S9O.dvi (1 page, 208 bytes).
sh-3.2$
答案1
如果我继续pdftex
跑
\tracingstats=1 \bye
日志文件将报告
Here is how much of TeX's memory you used:
2 strings out of 494671
95 string characters out of 6148970
14212 words of memory out of 5000000
1670 multiletter control sequences out of 15000+600000
14794 words of font info for 50 fonts, out of 8000000 for 9000
1420 hyphenation exceptions out of 8191
1i,0n,0p,1b,6s stack positions out of 5000i,500n,10000p,200000b,80000s
如果我运行它
\tracingstats=1 \input expl3-generic \relax \ExplSyntaxOn \bye
我明白了
Here is how much of TeX's memory you used:
6750 strings out of 494671
132558 string characters out of 6148970
103191 words of memory out of 5000000
8405 multiletter control sequences out of 15000+600000
14794 words of font info for 50 fonts, out of 8000000 for 9000
1420 hyphenation exceptions out of 8191
22i,0n,31p,10374b,291s stack positions out of 5000i,500n,10000p,200000b,80000s
expl3
因此,通过比较空文件和有文件的文件,您就可以了解内存的负载是多少\input expl3-generic
。
运行仅在开头添加的测试文件\tracingstats=1
时,我收到错误
! TeX capacity exceeded, sorry [number of strings=494671].
日志文件显示
Here is how much of TeX's memory you used:
494671 strings out of 494671
5388582 string characters out of 6148970
4493699 words of memory out of 5000000
496323 multiletter control sequences out of 15000+600000
14794 words of font info for 50 fonts, out of 8000000 for 9000
1420 hyphenation exceptions out of 8191
23i,0n,31p,10361b,291s stack positions out of 5000i,500n,10000p,200000b,80000s
如果指令中的替换文本\cs_new:cn
较长,内存会更快耗尽。
TeX 运行期间无法获取有关内存的信息。LuaTeX 中不存在此限制,请参阅手册中有关该status
库的 4.13 节。