Re: Remove and delete on an array...
On Apr 8, 2005, at 11:33 AM, Bradford W Miller wrote:
>> Do you think lisp programmers are generally aware that using delete
>> leaves references lying around? and of the consequences to memory
>> management?
>
> [BWM ] Yes, most of us are aware. Some implementations, such as Franz's
> include a facility called weak arrays and weak vectors. An object is
> not
> counted as live if the only references to it are via weak arrays or
> vectors; this is one way to deal with the problem you describe.
No, this won't work. For this to work only the stuff after the fill
pointer would be weakly referenced, the stuff before would be strongly
referenced. I'd rather just nil it out.
> However,
> removing a reference for a potentially unnecessary object is always a
> good
> idea,
This is the issue -- the *only* issue -- I've been raising about
delete. Unfortunately, for some reason, this doesn't appear to be
considered a good idea in CL, or I would have thought that this would
have been implemented. If it *is* implemented, *what* implements it
(and this was the question I asked in the very first post).
> though frankly for arrays that generally only happens when one no
> longer needs the entire array.
So arrays are temporary short-term data structures? Frankly, I can't
recall the last time that happened in my code. Maybe if I was using
arrays for multiple results, but I don't have to do that in lisp.
> In other words, the kinds of operations you appear to be performing are
> not those one typically uses an array for, in any language.
Sorry, I disagree. Strongly.
> In particular,
> the index of an array element is not expected to change for the
> lifetime
> of an array;
I just want to do what delete does but without introducing extra
references to the last thing in the array.
> if the frequency of removing elements is so small, you could
> bitblt and cons up a new array from the two portions of your existing
> array, and then delete the reference to your old array.
I think setting the non-nil elements after the fill pointer to nil is
an easier way.
> Alternatively, I'd
> suggest a quick course on data structures where exposure to other
> representations might help you develop the appropriate structure and
> API
> you need to suit your challenge.
I have a clear understanding of my requirement. I'm surprised it is
considered a challenge by *anybody*.
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
>
----
Bob Hutchison -- blogs at <http://www.recursive.ca/hutch/>
Recursive Design Inc. -- <http://www.recursive.ca/>
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________