Hi,
It is some Cache implementation from sandbox, it doe's not implements Map
interface,
but some ideas can be useful, it implements LRU, but doe's not lose
referenced values.
And I think it is no need for Reference map abstarction it is three
Reference types in JAVA
and all of them do almost the same in practice.
----- Original Message -----
From: "Jack, Paul" <[EMAIL PROTECTED]>
To: "'Jakarta Commons Developers List'" <[EMAIL PROTECTED]>
Sent: Tuesday, May 28, 2002 5:48 PM
Subject: RE: [SUBMIT][Collections] ReferenceMap, take 2


> > Just an idea....is it possible to write ReferenceMap as a
> > wrapper around
> > another Map? If so, then we could have ReferenceSortedMap,
> > ReferenceList
> > etc. all within ReferenceCollections.
>
> Yes, but not efficiently.  For weak or soft keys, you'd have
> to create a bunch of Reference objects that you don't actually
> need:
>
>    public Object get(Object key) {
>       key = toReference(keyType, key);
>       Object value = underlyingMap.get(key);
>       if (valueType > HARD) return ((Reference)value).get();
>       return value;
>    }
>
> Also I'm not convinced it's possible to write the iterator
> effectively:  The hasNext() method must guarantee that the
> next call to next() will return a valid object; however, the
> Reference to that object might have cleared between the
> call to hasNext() and next().  (Though I haven't spent too
> much time thinking about this problem, there may be perfectly
> sound solutions to it).
>
> Though it would be nice to have a referenced SequencedHashMap
> or LRUMap.
>
> Also purging elements from an arbitrary list would be an
> expensive operation (you'd have to traverse the entire list
> looking for the purged element, and then invoke remove(index),
> which would traverse the list again for a sequential list or
> require a memory copy for a random access list).
>
> > Also, in your tests I noted that you call System.gc() to
> > cause the garbage
> > collector to run. Does this not just 'suggest' that the gc be
> > run, thus
> > making the tests unreliable?
>
> It's true.  The tests should use their own ReferenceQueue
> to wait until the objects have been GC'd.  I'll modify the
> tests accordingly.
>
> -Paul
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>

Attachment: SoftRefMemoryCache.java
Description: Binary data

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to