[saga-rg] context problem

Andre Merzky andre at merzky.net
Thu Jul 20 10:24:21 CDT 2006


Hi Steve, 


Quoting [sbrandt at cct.lsu.edu] (Jul 20 2006):
> 
> I'll just state the obvious here....
> 
> You could always make a C++ Ptr class that wraps access to a pointer  
> and does reference counting.  If the objects in question do not  
> contain cyclic graphs, that would make things work just like java.

Actually, that is more or less what we do :-).
We use boost::shared_ptr for that.  Hence, the wrapper class
gets actually copied, but the shared_ptr only increments the
ref count in that case...

Cheers, Andre.



> If they do contain cyclic graphs, you could at least arrange things so  
> that when you delete one copy of your Ptr<T>, all of them get set to 0  
> -- thus allowing you to test.
> 
> Cheers,
> Steve
> 
> Quoting Andre Merzky <andre at merzky.net>:
> 
> >Hi Pascal,
> >
> >Quoting [Pascal Kleijer] (Jul 20 2006):
> >>>
> >>>>In the case of non-OO languages it might be preferable to use by copy
> >>>>then by reference, this will however have an impact on the runtime but
> >>>>will avoid you a lot of troubles.
> >>>
> >>>I would assume that a non-OO implementations uses pointers
> >>>to structures as object representations, or handles or such.
> >>>Hence a copy would in fact represent a reference-copy, and
> >>>the same semantics can easily be achieved.
> >>
> >>Well no. The problem with non-OO languages and C++ is that you must
> >>explicitly garbage collect your objects (call a destroy). So if you just
> >>copy the pointer you cannot test if it has been destroyed unless you
> >>handle the pointer to the pointer and can test for a NULL (agrl in
> >>Fortran). So the idea is to make a full copy of the object state and use
> >>a locale copy within the thread. This might cause a big overhead and be
> >>rather tricky to implement, especially if object contains other objects.
> >>The recursion in copy might be either impossible, longish or very complex.
> >
> >I disagree, and for two reasons even (that must be worth
> >something :-)
> >
> >For one, as I said in the thread earlier, I think that deep
> >copy raises huge semantic problems:
> >
> >  task t_1 = file.seek <saga::task::task> (100, saga::file::SeekSet);
> >  task t_2 = file.read <saga::task::task> (1, buf, &out);
> >
> >  t_1.run ();
> >  t_1.wait ();
> >
> >  t_2.run ();
> >  t_2.wait ();
> >
> >I, as a user, would assume that the read reads byte number
> >100.  But if we do a deep copy on task creation, the object
> >state (e.g. the file pointer) gets _copied_.  So the seek
> >operates on a different file pointer than the read, and the
> >read in fact returns the first byte in the file.
> >
> >That breaks a large number of use cases.
> >
> >
> >
> >Secondly, you are right, C++ and C must handle destruction
> >explicit - but that does not mean that you cannot copy
> >references.  It just means that your implementaion needs to
> >keep track of them!
> >
> >Now, that might be difficult, but (a) there are many libs
> >and tools helping with that and there also exist known
> >practices on how to do that, and (b) SAGA is about
> >ease-of-use, not ease-of-implementation.
> >
> >
> >Hehe, now you need three counterarguments :-)  Lets see what
> >you come up with :-D
> >
> >Cheers, Andre.
> >
> >
> >--
> >"So much time, so little to do..."  -- Garfield
> >
> >
> 
> 



-- 
"So much time, so little to do..."  -- Garfield





More information about the saga-rg mailing list