On 1/26/2017 5:02 PM, Sašo Živanović wrote:
On 24. 01. 2017 17:33, Hans Hagen wrote:
\def\csnewlocalbox#1{\expandafter\newlocalbox\csname #1\endcsname}
\def\csboxnumber#1{\expandafter\number\csname #1\endcsname}

\starttext

\newbox\MyBoxA \number\MyBoxA

\dorecurse{2} {
    \dorecurse{1000} {
        \csnewlocalbox{TempBox#1-1}%
        \csnewlocalbox{TempBox#1-2}%
        \csnewlocalbox{TempBox#1-3}%
        \csnewlocalbox{TempBox#1-4}%
        \csnewlocalbox{TempBox#1-5}%
    }
    \writestatus{!!!}{#1 million done}
    #1: \csboxnumber{TempBox#1-1}\par
    #1: \csboxnumber{TempBox#1-2}\par
    #1: \csboxnumber{TempBox#1-3}\par
    #1: \csboxnumber{TempBox#1-4}\par
    #1: \csboxnumber{TempBox#1-5}\par
}

\newbox\MyBoxB \number\MyBoxB

\stoptext

even then you only get 5000 boxes defined ...
Well, that's because I was impatient and have changed a 1000000 to a
1000 ;-)
you can reset the storag
of course but you still have 5000 hash entries (mening \undefined then)
with names like TempBox*-*
That's very good info, thanks!

\starttext

\bgroup
  \newlocalbox\foo
  \setbox\foo\hbox\bgroup
    bar
    \ifdefined\oof\else\newbox\oof\fi
    \global\setbox\oof\hbox{foo}
  \egroup
\egroup

\box\oof

\stoptext

when we would reset the allocator count then \oof would still be ok but
its slot would be reallocated at some point by \newlocalbox
I hope you don't mind explaining this further, as I'm lost.

1. I was unable to produce this effect. Should it happen with the
\newlocalbox defined in this thread, or some hypothetical \newlocalbox
(which would share the allocation counter with \newbox?). I tried both
your \newlocalbox and elocalloc's \locbox, and didn't manage to
reallocate \oof's register.

But maybe this question is bogus, as:

2. I don't understand why it is important to use \newbox within
\setbox\foo\hbox{...}  Don't we get the same result in the following?

\starttext

\bgroup
  \newlocalbox\foo
  \setbox\foo\hbox\bgroup
    bar
  \egroup
  \ifdefined\oof\else\newbox\oof\fi
  \global\setbox\oof\hbox{foo}
\egroup

\box\oof

\stoptext

the difference is that a next \newbox\oof will report that \off is already defined (so no new box will be allocated unless you \relax \foo) while \newlocalbox\foo will happily reuse \foo and not report a message (as you use it local \foo is also defined as local while \oof is global)

Hans



--

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
_______________________________________________
dev-context mailing list
dev-context@ntg.nl
https://mailman.ntg.nl/mailman/listinfo/dev-context

Reply via email to