Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Efficiency question

2 views
Skip to first unread message

pineapple

unread,
Sep 6, 2009, 3:31:47 PM9/6/09
to
How does APL handle existing variables on the right side of
"replicate," "take" etc?

Between these alternatives (and more):

:If T<0 ⋄A←B ⋄:EndIf

A←T (T<0)/A B

A←T↑A B

I prefer to write the second or third one. However, my question is
whether APL needs to create copies in memory of A and B on the right
side of that "replicate" or "take." If so, I guess the :If would be
more efficient, and I'd use that (confronting this issue in a piece of
code right now).

In the big scheme of things, I guess it really isn't important. But
I'm just curious and would like to know.

Bob Smith

unread,
Sep 6, 2009, 5:29:53 PM9/6/09
to

I can't say for sure about other implementations, but my guess is that
quite likely most implementations nowadays use reference counts on
arrays instead of making wholesale copies. That is, the strand A B
produces a two-element vector consisting of a pointer to A and a pointer
to B. The reference counts of A and B are each incremented to reflect
that there are now two copies of A and B -- one each in A, B, and A B.

This way, if the user deletes (say) A, its reference count is
decremented (down to one), but as it isn't zero, the storage for A isn't
released (there's still a reference in A B). If that strand is (say) a
temporary and is deleted, then the reference count for A goes down to
zero and its storage is released.

Note that reference counts also obviate the need to make wholesale
copies when passing a named array to a user-defined function/operator.

BTW, this may sound straightforward, however it can get complicated and
reference count bugs are notoriously hard to find. Any other
implementors find that to be the case, or is it just me?

--
_________________________________________
Bob Smith -- bsm...@sudleydeplacespam.com

To reply to me directly, delete "despam".

0 new messages