Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!uakari.primate.wisc.edu!polyslo!ttwang From: ttwang@polyslo.CalPoly.EDU (Thomas Wang) Newsgroups: comp.lang.c++ Subject: Re: Support for movable objects in C++ Message-ID: <1989Oct4.161939.12442@polyslo.CalPoly.EDU> Date: 4 Oct 89 16:19:39 GMT References: <1989Sep30.051559.20644@polyslo.CalPoly.EDU> <6590275@hplsla.HP.COM> Reply-To: ttwang@polyslo.CalPoly.EDU (Thomas Wang) Distribution: usa Organization: Cal Poly State University -- San Luis Obispo Lines: 75 I have come up with what I think is a better alternative than 'volatile classes'. Instead of using master pointers, each member function is required to declare a local variable of 'watcher_t'. The 'watcher_t' class keep track of the address of 'this' on the stack. When the objects are moved, a post watcher list traversal will make all the values of 'this' point to the right location. This means that I can use modern GC methods with real copying. #ifndef WATCHER_T #define WATCHER_T // File: watcher_t.h // Author: Thomas Wang // Purpose: watch the value of 'this' on the stack & fix them when necessary // Date: Oct 3, 1989 // Usage: put watcher_t watcher(&this); at start of every member function class watcher_t { friend class gc_root_t; int* this_location; watcher_t* prev_link; watcher_t* next_link; void update_this(); // make 'this' point to the right location public: watcher_t(void*); // constructor telling the address of 'this' for gc objects ~watcher_t() { prev_link->next_link = next_link; next_link->prev_link = prev_link; } }; #endif // File: watcher_t.cc // Author: Thomas Wang // Purpose: watch the value of 'this' on the stack & fix them when necessary // Date: Oct 3, 1989 // Usage: put watcher_t watcher(&this); at start of every member function #include "watcher_t.h" // make 'this' point to the right location void watcher_t::update_this() { static int* forward_ptr; forward_ptr = this_location - 1; if (*forward_ptr) *this_location = *forward_ptr; // fix the value of 'this' } // constructor telling the address of 'this' for gc objects watcher_t::watcher_t(void* val) { this_location = (int*) val; the_root.insert_watcher(this); } -Thomas Wang ("This is a fantastic comedy that Ataru and his wife Lum, an invader from space, cause excitement involving their neighbors." - from a badly translated Urusei Yatsura poster) ttwang@polyslo.calpoly.edu