From: Austin Ziegler Date: 2005-09-07T03:41:09+09:00 Subject: Re: Efficient Object Reconstruction? On 9/6/05, Pit Capitain wrote: > Austin Ziegler schrieb: >> The attached program demonstrates this behaviour using >> Transaction::Simple. Any ideas, anyone? > This seems to be a problem with the implementation of > Transaction::Simple. Well, yes. This is part of the reason that I'm trying to figure out how to fix it. It's not a *huge* problem, but it *is* an annoying one. > The problem occurs when you have two objects that hold references to > each other, say o1 and o2. When you start a transaction on o1, you > store the current state as a Marshal dump of the object graph: > > o1 <-----> o2 > > When you rewind the transaction, you restore the Marshal dump. The > resulting object graph contains new objects o1' and o2', holding > references to each other. > > o1' <-----> o2' > > Since you don't want to return the new object o1' but reuse the > original object o1, you replace all the instance variables of o1 by > those of o1'. The resulting object graph then looks like this: > > o1' <-----> o2' <----- o1 <----- o2 > > I fear that a fix for this problem wouldn't fit into > Transaction::*Simple* :-( That's, um, more or less what's going on. What's interesting is that it only matters when attributes *aside* from containment change during the transaction. Got any recommendations on how to fix it ... preferably without walking the object graph? The long term goal is to do something like this: pdf.start_transaction # stores pdf as pdf' # make modifications pdf.rewind_transaction # replace pdf with pdf' # make modifications pdf.commit_transaction # keep pdf It's the *replace* that I'm having a problem with, and I suspect that this isn't something I can do without, say, evil.rb. Does anyone have any suggestions on how might this might be done? I noticed this a while back (and implemented an API change to gloss over it) when I was trying to make it so that one could choose to compress a PDF document on save rather than when it's created. I suspect (strongly) that I could also save on PDF::Writer memory use if I could get this working (and working quickly). It might be acceptable to require a migration to Transaction::Full or something as yet unwritten, but I *want* it to be pure Ruby, if possible. (Otherwise, it'll be something that I make a run-time option.) -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca