There is a usecount that indicates the number of names that refer to a
block. This is incremented when there is an assignment.
There is also a stack (called the NVR stack) that is updated every time
the parser moves a name from its queue to its execution stack. The NVR
stack is used to defer freeing a block: consider
(a =: 1) [ a
right-to-left, the value of a is stacked, then a is reassigned. This
would free the value of a, which is disastrous because a pointer to it
is on the stack. So assignment always runs through the NVR stack to see
if there is a reference to the value about to be assigned. If so, the
earliest such one is tagged as representing a deferred free; the old
value of a is then not freed until the sentence containing the deferred
free completes. Note that the reference to a could have come in a
higher-level sentence.
I would fix the problem we are discussing by having the code that is
about to do an in-place assignment run a check on the NVR stack to see
if the name is in use in a higher sentence (it will always be in use in
the sentence containing the in-placeable assignment). If the name is in
use, the assignment would not be performed inplace. This is fast, since
inplace assignments are rare.
Henry
On 6/21/2016 3:48 PM, Raul Miller wrote:
Do you think it's faster to do a stack scan on each in-place update
than to update an "in play" count each time that stack gets updated?
Thanks,
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm