Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / April 2006

Tip: Looking for answers? Try searching our database.

Constant unification - what's the best approach?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ole Nielsby - 31 Mar 2006 21:02 GMT
I need a mechanism for unifying constant objects.

Sort of like a generalization of String.Intern.

The constants can be nested (think pure Lisp or
immutable DOM).

I need a kind of weak-reference dictionary, so that
garbage constants will automatically be removed.

At present, the best idea I can come up with is to
use a System.SortedDictionary and populate it
with wrappers based on weak references. The
constant objects will refer back to their wrappers,
and their finalizer will remove them from the
dictionary. The wrappers will be compared by
comparing the wrapped constants.

I'm not too happy about this idea. When a constant
has been created (which will happen very frequently),
a weak reference wrapper will have to be created
before the dictionary lookup - I'd rather postpone
this and only do it when the lookup produces no
match.

Besides, it seems the WeakReference prevents me
from writing verifiable code, though I'm not sure
about this.

Any other ideas?

Is an open-source/shared-source implementation
of SortedDictionary (or similar) available? This
might be a good starting point for me in constructing
a better solution.

Btw, is there a generics version of WeakReference?

Thanks/Ole N.
Guffa - 19 Apr 2006 18:27 GMT
> Btw, is there a generics version of WeakReference?

Not until now:

public class WeakReference<T> : WeakReference {

    public WeakReference(T target) : base(target) {}
    public WeakReference(T target, bool trackResurrection) : base(target,
trackResurrection) {}
    protected WeakReference(System.Runtime.Serialization.SerializationInfo
info, System.Runtime.Serialization.StreamingContext context) : base(info,
context) {}

    public new T Target {
        get { return (T)base.Target; }
        set { base.Target = value; }
    }

}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.