Hi,

2009/4/30 Stuart Sierra <the.stuart.sie...@gmail.com>:
>
> On Apr 29, 5:58 pm, Stu Hood <stuh...@gmail.com> wrote:
>> Instead of attaching the metadata directly to the object, what if the
>> metadata was stored outside the object, in a global map of {object metadata,
>> ...}? In order to handle garbage collection, something similar to Java's
>> WeakHashMap could be used, with the object itself as the key.
>
> Interesting idea.
>
> There might be performance penalities, depending on how often metadata
> is used.  Metadata guarantees atomic updates (alter-meta!) so the
> WeakHashMap might need to be wrapped in a synchronized map, at a
> further penalty.

I guess this would not be sufficient: WeakHashMap are not side-effect
free: they mutate every time one of their key is removed :
"When a key has been discarded its entry is effectively removed from
the map, so this class behaves somewhat differently than other Map
implementations."

, making them improper to be used within STM transactions and such.

Regards,

-- 
Laurent


>
> I've never needed metadata on non-Clojure types.  Do you have a use in
> mind?
>
> This could be a library, too, sort of like:
>
> (defn my-meta [object]
>  (if (instance? clojure.lang.IMeta object)
>      (meta object)
>      (*global-metadata* object)))
>
> -SS
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to