
On 01/11/2006 10:39 AM, Achilleas Margaritis wrote: [snip]
1) allocated the storage for the pointee 2) stored the last-created-pointer in some thread-local-storage 3) created the pointee with placement new (this requiring knowlege about the pointee's CTOR) 4) then zeroed the last-created-pointer
Does this make sense? [snip]
No, the new object will be placed in a thread-local-storage list by operator new.
Here is the sequence of operations:
1) operator new is invoked: it allocates memory for the new block and places the block in a thread-local-storage object list. 2) gc_ptr::CTOR is invoked: it looks at the last entry of the thread-local-storage object list. If not inside that block, it adds itself to the thread-local-storage pointer stack.
-------------- cut here ------------- The only gc_ptr on the stack is on_stk.other; yet,
OK, but in my mental trace of the following code: <------------- cut here -------------- class MyClass : public gc_object { public: gc_ptr<MyClass> other; MyClass(unsigned n=0) : other(n?new MyClass(n-1):(MyClass1*)0) {} }; MyClass on_stk(3); the others are put on the stack because, in each case, the last created gc_object is the one used in the argument to the gc_ptr CTOR. Am I missing something? If so, could you maybe do a quick prototype to illustrate what I'm missing? TIA.