Ruby's callcc captures the current continuation, which can be subsequently called to restore the control, but not the data. I would like to capture the current continuation along with the current image of the memory.
It seems to me that capturing the heap shouldn't be very difficult; I can rely on ObjectSpace::each_object and ObjectSpace::dump_all, or Marshal.dump, or simply Object.clone. However, I don't see any straightforward way to restore the heap. Ideally, I would like to traverse the object_id -> object map, restoring the old image of the object for every object_id (and re-adding the object_id if the corresponding object had been GC'd). Unsurprisingly, there is no Ruby-level api that lets me do this. I am wondering if there are any low-level hooks to Ruby's GC that I can use.
Any help is appreciated, including suggestions about alternative approaches.
How about pushing each on to a stack? Then you can keep popping off the stack to retrieve the data.
https://github.com/bvsatyaram/Ruby-Data-Structures