caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: Weak pointers
       [not found] <199703181607.RAA13208@tobago.inria.fr>
@ 1997-03-18 17:08 ` Kohler Markus
  1997-03-19  7:45   ` Weak pointers (summarize) Kohler Markus
  0 siblings, 1 reply; 2+ messages in thread
From: Kohler Markus @ 1997-03-18 17:08 UTC (permalink / raw)
  To: Damien Doligez; +Cc: caml-list

> >But how do you know then that value is not valid anymore ?
> 
> What do you mean by "valid" ?  It remains valid as long as the GC has
> not deallocated it.  And the weak pointer is erased before the value
> is deallocated.
>  
> >The same could be done with a "normal" pointer. 
> 
> A normal pointer will never let the GC deallocate the value.

OK, I think i got the point, as long as you only use the hash table internally 
for adding, it's not a problem. 

If you use the hashtable to directly access specific nodes, you are running 
into trouble. If you want this feature, weak pointers are not usefull. 

It depends on what you want to do with your datastructure. 

If you "only" use your datastructure as a tree you probably want that only one 
node A is deleted if you call delete(A) for example. In this case you just 
delete ONE specific pointer to node A. 

If you want support operations like "delete all nodes A in the tree", it 
really means you have implemented a graph operation.  

In this case you have to delete ALL pointers to A.  


Regards, 
Markus

-- 
+----------------------------------------------------------------------------+
| Markus Kohler                          Hewlett-Packard GmbH                |
| Software Engineer                      Network & System Management Division| 
|                                        IT/E Success Team                   |
+----------------------------------------------------------------------------+







^ permalink raw reply	[flat|nested] 2+ messages in thread

* Weak pointers (summarize)
  1997-03-18 17:08 ` Weak pointers Kohler Markus
@ 1997-03-19  7:45   ` Kohler Markus
  0 siblings, 0 replies; 2+ messages in thread
From: Kohler Markus @ 1997-03-19  7:45 UTC (permalink / raw)
  To: caml-list


I would like to summarize our discussion about weak pointers. 

1. There are some rare cases were weak pointers are usefull  to implement 
shared datastructures efficiently. This is probably even more important for 
distributed data structures where message sending can be  expensive. 
It  works on your example, because it doesn't matter if the weak pointer 
points to valid data or not.  

2. One have to be very carefully when using weak pointers. One example is 
extending our tree datastructure by an hash based access method. this would 
not work anymore with the weak pointer structure. 

3. There are other perhaps more clean solutions for that problem :
Since we know that every problem can be solved by an additional level of 
indirection, the following solution would be possible. 



		| | |
		Proxy
	Hashtable |
	    |_____A


All pointers to nde a in the tree woudl have to point to a Proxy object, 
instead of pointing directly to object A. 

When all pointers to the Proxy object are gone it would go away and send a 
finalize message to A. A would then inform all it dependent objects "hey i'm 
going to be finalized". The dependent objects could then do the appropriate 
actions. 



4. It would be really nice if pointers would be objects too. The solution in 3 
could the be implemented transparently.  

Any comments ?

Markus  

-- 
+----------------------------------------------------------------------------+
| Markus Kohler                          Hewlett-Packard GmbH                |
| Software Engineer                      Network & System Management Division| 
|                                        IT/E Success Team                   |
+----------------------------------------------------------------------------+







^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-03-19 13:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <199703181607.RAA13208@tobago.inria.fr>
1997-03-18 17:08 ` Weak pointers Kohler Markus
1997-03-19  7:45   ` Weak pointers (summarize) Kohler Markus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).