www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Weak references

reply Jesper Nordenberg <jesper nnl.se> writes:
I'm new to D. Are there any equivalents of Java's WeakReference and 
SoftReference in D? What is the recommended IDE for developing in D?

/Jesper
Dec 09 2004
next sibling parent reply Sebastian Beschke <s.beschke gmx.de> writes:
Jesper Nordenberg wrote:
 What is the recommended IDE for developing in D?
Depends on who you ask :) I'll go ahead and recommend Ant's LEDS at http://leds.sf.net/ even though I've never used it. Apart from that, jEdit (http://www.jedit.org/) is doing quite OK for me, too :)
 
 /Jesper
Dec 09 2004
parent Ant <Ant_member pathlink.com> writes:
In article <cp9uft$o0v$1 digitaldaemon.com>, Sebastian Beschke says...
Jesper Nordenberg wrote:
 What is the recommended IDE for developing in D?
Depends on who you ask :) I'll go ahead and recommend Ant's LEDS at http://leds.sf.net/ even though I've never used it.
this is the greatest compliment, no not toleds, but to my marketing strategy until now! :) of course it's http://leds.sourceforge.net/ (see, I never loose an opportunity to divulgate leds url!)
Apart from that, jEdit (http://www.jedit.org/) is doing quite OK for me, 
too :)
also check http://www.prowiki.org/wiki4d/wiki.cgi?EditorSupport Ant
Dec 09 2004
prev sibling parent reply Ben Hinkle <bhinkle4 juno.com> writes:
 Are there any equivalents of Java's WeakReference and
 SoftReference in D? 
nope. I don't have any links handy but I remember it coming up on the newsgroup before and it didn't seem likely to show up any time soon if at all. It complicates the GC too much (or something like that) for too little benefit. -Ben
Dec 09 2004
next sibling parent reply Jesper Nordenberg <jesper nnl.se> writes:
Ben Hinkle wrote:
Are there any equivalents of Java's WeakReference and
SoftReference in D? 
nope. I don't have any links handy but I remember it coming up on the newsgroup before and it didn't seem likely to show up any time soon if at all. It complicates the GC too much (or something like that) for too little benefit.
Too bad. I think weak references are very useful when creating loosely coupled classes. /Jesper
Dec 10 2004
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Jesper Nordenberg" <jesper nnl.se> wrote in message 
news:cpbn88$h1u$1 digitaldaemon.com...
 Ben Hinkle wrote:
Are there any equivalents of Java's WeakReference and
SoftReference in D?
nope. I don't have any links handy but I remember it coming up on the newsgroup before and it didn't seem likely to show up any time soon if at all. It complicates the GC too much (or something like that) for too little benefit.
Too bad. I think weak references are very useful when creating loosely coupled classes. /Jesper
Can you give more details? The current design won't change without making an argument to change it and the argument will heavily depend on use cases and how hard the alternative designs are. So the more examples we have of people using weak references the better.
Dec 10 2004
parent reply Jesper Nordenberg <jesper nnl.se> writes:
Ben Hinkle wrote:
Too bad. I think weak references are very useful when creating loosely 
coupled classes.

/Jesper
Can you give more details? The current design won't change without making an argument to change it and the argument will heavily depend on use cases and how hard the alternative designs are. So the more examples we have of people using weak references the better.
I typically use weak references for listeners in Java. You might have an object A listening on another object B, but you don't want to prevent A from being GC'ed just because B keeps a reference to it. When there are no other references to A beside the one in B, you want the listener to be automatically removed from B. This scenario is very common in for example GUI applications. Another scenario is when you want to minimize the dependencies between classes and thus store information about an object in a map rather than storing the information inside the object. When the object is GC'ed you want to remove the entry from the map. In Java this is easily solved by using a WeakHashMap which automatically removes the key-value pair from the map when the key is GC'ed. Maybe there are other ways besides weak references to solve this in D. /Jesper
Dec 10 2004
parent reply Vathix <vathix dprogramming.com> writes:
On Fri, 10 Dec 2004 16:27:17 +0100, Jesper Nordenberg <jesper nnl.se>  
wrote:

 Ben Hinkle wrote:
 Too bad. I think weak references are very useful when creating loosely  
 coupled classes.

 /Jesper
Can you give more details? The current design won't change without making an argument to change it and the argument will heavily depend on use cases and how hard the alternative designs are. So the more examples we have of people using weak references the better.
I typically use weak references for listeners in Java. You might have an object A listening on another object B, but you don't want to prevent A from being GC'ed just because B keeps a reference to it. When there are no other references to A beside the one in B, you want the listener to be automatically removed from B. This scenario is very common in for example GUI applications.
I had to do this for a few things in DFL, like menus. I accomplished it by storing the reference in malloc'd memory.
Dec 10 2004
parent reply Bastiaan Veelo <Bastiaan.N.Veelo ntnu.no> writes:
Vathix wrote:
 On Fri, 10 Dec 2004 16:27:17 +0100, Jesper Nordenberg <jesper nnl.se>  
 wrote:
 
 Ben Hinkle wrote:

 Too bad. I think weak references are very useful when creating 
 loosely  coupled classes.

 /Jesper
Can you give more details? The current design won't change without making an argument to change it and the argument will heavily depend on use cases and how hard the alternative designs are. So the more examples we have of people using weak references the better.
I typically use weak references for listeners in Java. You might have an object A listening on another object B, but you don't want to prevent A from being GC'ed just because B keeps a reference to it. When there are no other references to A beside the one in B, you want the listener to be automatically removed from B. This scenario is very common in for example GUI applications.
I had to do this for a few things in DFL, like menus. I accomplished it by storing the reference in malloc'd memory.
I am very interested in this. Where can I find the details? Bastiaan.
Dec 11 2004
parent Vathix <vathix dprogramming.com> writes:
   I had to do this for a few things in DFL, like menus. I accomplished  
 it by  storing the reference in malloc'd memory.
I am very interested in this. Where can I find the details?
Something like this. It's just an idea, it won't compile as-is: class Item // Item you want weak references to. { this() { addItem(this); } ~this() { removeItem(this); } } Item[] refItems; // malloc'd memory holding weak references to Item`s. void addItem(Item item) { refItems = realloc(refItems, count * Item.sizeof); refItems[i] = item; } void removeItem(Item item) { int i; for(i = 0; i != refItems.length; i++) { if(item == refItems[i]) { refItems = realloc(refItems, count * Item.sizeof); break; } } }
Dec 11 2004
prev sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Ben Hinkle wrote:
Are there any equivalents of Java's WeakReference and
SoftReference in D? 
nope. I don't have any links handy but I remember it coming up on the newsgroup before and it didn't seem likely to show up any time soon if at all. It complicates the GC too much (or something like that) for too little benefit.
It is possible to create them (without altering the GC), but it takes some rather arcane magic to do it.
Dec 10 2004