[Borges-users] suggestion: snapshots without weakrefs
Eric Hodel
drbrain at segment7.net
Tue May 25 13:59:12 EDT 2004
??????? ???????? (slepnev_v at rambler.ru) wrote:
> because weakrefs+continuations turned out so buggy (and ignored by
> ruby-core), I designed a way to snapshot stuff without weakrefs. The
> idea is to keep an anonymous module for each session, and use
> ObjectSpace.each_object(mod) to create snapshots. The snapshots of
> objects don't keep their class - just their instance variables, so
> snapshots aren't eligible for snapshotting again. I've unit-tested the
> stuff a bit (though not with Borges yet), and it seems to work.
This looks very nice, I'm very interested in seeing an integrated
patch...
[snip details]
> Here's the source, it's not optimal yet, much room for improvement:
>
> module BacktrackMixin
>
> def shallow_copy
> copy_instance_variables(self,Object.new)
> end
>
> def restore_from(copy)
> copy_instance_variables(copy,self)
> end
>
> private; def copy_instance_variables(src,dest)
> src.instance_variables.each do |name|
> dest.instance_variable_set(name,
> src.instance_variable_get(name))
> end
> return dest
> end
>
> end
>
> class Snapshot
>
> def initialize(mod)
> @snap = {}
> ObjectSpace.each_object(mod) {|obj| @snap[obj] =
> obj.shallow_copy}
> end
This fetches each object that includes mod, right? Nifty!
(Since Module.new { include Backtrack } is unique, it only gathers
those objects including exactly that instance, right?)
> def restore
> @snap.each {|k,v| k.restore_from v}
> end
>
> def size; @snap.size end
>
> end
--
Eric Hodel - drbrain at segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/borges-users/attachments/20040525/74863ec7/attachment.bin
More information about the Borges-users
mailing list