From: Arnold Snarb on
Matthias Meier wrote:
> Alexandre Ferrieux asked:
>> But may I ask what you're trying to do ?
>
> I have an tcl-interpreter in a long running (c-written) server-process.
> During server livetime various scripts [...] are interpreted
> and i want to ensure that the scripts are don't affect each other. [...]
>
> Therefore i would like to evaluate each script in a 'new'/clean interpreter.
>
> But creating a new interpreter ( Tcl_CreateInterp() ) every time
> would consume too much time.


Have you tried it? Have you measured it?

Is it *actually* too slow, or does it just seem like the
kind of thing that *you think* maybe might be too slow?


> Because the problem is time-critical im looking for the most
> performant way to 'reset' the interpreter.
> (I hoped there is a more performant way to do it then unsetting
> the vars one by one)

The fastest way I know of to get a new/clean interpreter
is to create a new one.

I'd try that first.

If that turns out to be too slow -- actually and truly for real
too slow -- then measure it, time it, and ask here again.
(There are a few tricks you can use to speed interp creation up).

But in any case, creating a new interp is most likely
going to be faster (and for certain going to be more reliable)
than trying to clean up an old one.


--arnie
From: Alexandre Ferrieux on
On May 3, 8:51 am, Matthias Meier <Me...(a)FuH-E.de> wrote:
> Alexandre Ferrieux schrieb:
>
> > On Apr 29, 11:39 am, Matthias Meier <Me...(a)FuH-E.de> wrote:
> >> Hello,
>
> >> i want to "reset" an Interpreter after evaluating a script to the state it was after initialisation.
> >> (that means: delete all the vars/procs which were created during the script-evaluation)
>
> > But may I ask what you're trying to do ?
>
> I have an tcl-interpreter in a long running (c-written) server-process.
> During server livetime various scripts (which have nothing to do with each other) are interpreted and i want to
> ensure that the scripts are don't affect each other.
> (i.E. just because one script uses variables (variable names) which an other Script uses too)
> Therefore i would like to evaluate each script in a 'new'/clean interpreter.
> But creating a new interpreter ( Tcl_CreateInterp() ) every time would consume too much time.
>
> Because the problem is time-critical im looking for the most performant way to 'reset' the interpreter.
> (I hoped there is a more performant way to do it then unsetting the vars one by one)

Note that the complexity/thoroughness of the solution depends on the
level of cooperation to be expected from the scripts:

- If you assume nothing (like 'they might even be viruses'), then the
only sure-fire is to nuke and recreate (I'd even respawn a process to
be on the safe side; yes I know you will label this as Too Slow).

- If reasonable cooperation is thinkable, then just [namespace eval]
them, and delete the namespace afterwards. Or even just [eval] them
from within a proc, and fall out of the proc afterwards. In both
cases, unqualified vars will *not* be globals, and will be removed
wholesale. Of course the "cooperation" means for the script to never
use [global] nor any explicit namespace.

- for procs I'm afraid there's no other way than the enumeration I
suggested, but it may be okay if your scripts are small enough to be
so exquisitely fast (otherwise, the sheer time to load tens of procs
would be too much anyway)

-Alex
From: Matthias Meier on
Arnold Snarb schrieb:
> Matthias Meier wrote:
>> Alexandre Ferrieux asked:
>>> But may I ask what you're trying to do ?
>> I have an tcl-interpreter in a long running (c-written) server-process.
>> During server livetime various scripts [...] are interpreted
>> and i want to ensure that the scripts are don't affect each other. [...]
>>
>> Therefore i would like to evaluate each script in a 'new'/clean interpreter.
>>
>> But creating a new interpreter ( Tcl_CreateInterp() ) every time
>> would consume too much time.
>
>
> Have you tried it? Have you measured it?

Tcl_CreateInterp() = 0,065s
Tcl_DeleteInterp() = 0,045s

==> 0,11s

(On a Quad-Core 3.20GHz Intel-Xeon)


>
> Is it *actually* too slow, or does it just seem like the
> kind of thing that *you think* maybe might be too slow?

It *is* too slow because users waiting for respose while 10 to 50 scripts are evaluated.
That would take 1 to 5 seconds just for creating and destroying the interpreter.


Thanks,
Matthias

>
>
>> Because the problem is time-critical im looking for the most
>> performant way to 'reset' the interpreter.
>> (I hoped there is a more performant way to do it then unsetting
>> the vars one by one)
>
> The fastest way I know of to get a new/clean interpreter
> is to create a new one.
>
> I'd try that first.
>
> If that turns out to be too slow -- actually and truly for real
> too slow -- then measure it, time it, and ask here again.
> (There are a few tricks you can use to speed interp creation up).
>
> But in any case, creating a new interp is most likely
> going to be faster (and for certain going to be more reliable)
> than trying to clean up an old one.
>
>
> --arnie