Re: (blead patch) New TRIE regex patch
by Demerphq other posts by this author
Mar 2 2005 12:53PM messages near this date
Re: (blead patch) New TRIE regex patch
|
Re: (blead patch) New TRIE regex patch
On Wed, 2 Mar 2005 19:46:43 +0000, Dave Mitchell <davem@[...].com> wrote:
> On Wed, Mar 02, 2005 at 05:20:36PM +0100, demerphq wrote:
> > What is the difference between the two sets? In my case should I use
> > ENTER/LEAVE or SAVETMPS/FREETMPS or both sets? Anybody who understands
> > these details who felt inclined to update the pod on this would find
> > me very grateful.
>
> There are two stacks in question, the save stack, and the tmps stack.
> Creating mortals (eg sv_2mortal() or sv_newmortal()) pushes a reference to
> that SV onto the tmpstack. FREETMPS frees all the items on the tmpstack
> down to the current floor. SAVETMPS sets a new floor. Typically FREETMPS
> is called once every statement (by pp_nextstate).
>
> On the other hand, ENTER sets a new floor on the savestack and LEAVE
> processes all the items on the savestack back down to the previous floor.
> The savestack is more general than the tmpstack; a whole bunch of things
> an be pushed onto the savestack, not just temporary values. Note that
> SAVETMPS actually saves the current tmpstack floor on the savestack.
>
> So.....
>
> If you just want to create a temporary value and are happy for it to be
> freed at the next statement, just create a new mortal SV. The danger with
> that is if your code gets involved in any sort of looping or recursion
> within a single op, where new tmps are created each time, then the
> tmpsstack will fill up with rubbish.
>
> If you want to set a new floor on the tmpstack and make sure its freed up
> earlier, then you want to do domething like:
>
> ENTER; # set new floor on savestack
> SAVETMPS; # push the current tmps floor onto the savestack;
> ...
> sv_newmortal(); # create new mortal(s)
> ...
> FREETMPS; # free all the mortals you've created
> LEAVE; # pop the item(s) off the savestack, causing
> # (possibly amongst other things) the old tmpstack
> # floor to be restored.
>
> If the code should die in the middle and be trapped by eval, then the
> LEAVE is called implicity.
Thanks this is great. Suitably massaged it should go into one of the
pods. (Maybe ill give it a whirl if noone else does.)
Ok, so if im not using mortals, but rather SAVEFREEPV it looks like
the data is being stored on the save stack and not the tmpstack. So do
i still need the SAVETMPS/FREETMPS? Can I not just use ENTER/LEAVE by
itself?
I also wonder if there is a way I can save a variable somehow so its
freed if the program dies, but otherwise is freed by myself. Is that
possible somehow?
Cheers,
Yves
--
First they ignore you, then they laugh at you, then they fight you,
then you win.
+Gandhi
Thread:
Yitzchak Scott-Thoennes
Demerphq
Demerphq
Yitzchak Scott-Thoennes
Dave Mitchell
Demerphq
Dave Mitchell
Demerphq
Dave Mitchell
Demerphq
Demerphq
Yitzchak Scott-Thoennes
Rafael Garcia-Suarez
|