On 1/24/2017 5:04 PM, Sašo Živanović wrote:
On 24. 01. 2017 16:36, Hans Hagen wrote:
On 1/24/2017 3:05 PM, Sašo Živanović wrote:
Dear Hans,

thank you very much for helping me out here.

Aditya's rephrasal of the question might have shown a tree but hidden
the forest ... ;-)  Let me try to explain below, but please also take a
look at my original post,
https://mailman.ntg.nl/pipermail/dev-context/2016/003346.html.

As far as I can see, in your 10 million example I can only work on one
of the local boxes at the time, whereas I need to save an undetermined
number of boxes, do some computation which uses dimensions of all these
boxes (this computation potentially invokes user's code, so I don't have
control over it), and then use all the saved boxes.
(Btw, saving just the dimensions is not an acceptable solution, both
because of speed and because in general, setting the box with same
content twice won't yield the same result.)

Just try it ...

\newbox\MyBoxA \number\MyBoxA

\dorecurse{2} {
    \dorecurse{1000000} {
        \newlocalbox\TempBoxA
        \newlocalbox\TempBoxB
        \newlocalbox\TempBoxC
        \newlocalbox\TempBoxD
        \newlocalbox\TempBoxE
    }
    \writestatus{!!!}{#1 million done}
    #1: \number\TempBoxA\par
    #1: \number\TempBoxB\par
    #1: \number\TempBoxC\par
    #1: \number\TempBoxD\par
    #1: \number\TempBoxE\par
}

\newbox\MyBoxB \number\MyBoxB

\stoptext

overhead: 5 boxes in 2*1 million (or more) allocations

But not if:

\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 ... you can reset the storag of course but you still have 5000 hash entries (mening \undefined then) with names like TempBox*-*

\starttext

\dorecurse{100}
  {\bgroup
   \dorecurse{10000}
     {\expandafter\def\csname foo:#1:##1\endcsname{}}
   \egroup}

\stoptext

so in the end it doesn't matter much that the boxes are allocated given that one reuses names

However, I see your point now. If I use a consistent naming scheme (and
I do) and allocate using \csnewlocalbox{node<id>@box}, the boxes will be
reused.


so, if a user needs 15.000 boxes locally you have an overhead of 15.000
but the second time if he/she uses the same names the overhead doesn't
grow ... in fact, if he/she uses 15K new names also the hash will get
them (even if they get undefined later)

As the number of needed boxes cannot be known in advance, I'd like to be
nice and "give them back" to the allocation system after using them. And
I *do* know how to do that (see localloc, elocalloc, or etex), but I'm
not sure if it would cause any trouble in ConTeXt: I'd prefer "not to
mess with allocation" indeed and have the issue fixed systemically.

no need to give them back ..
Well, imho, that's bad programming practice, but the fault goes all the
way back to plain TeX ...

and with the fact that we have a macro language with a grouping model and even worse, users who can do unexpected things like

\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


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