Boost logo

Boost :

From: Andy Glew (glew_at_[hidden])
Date: 1999-08-13 14:28:52

OK, so I asked y'all about live_ptr<T>,
aka a weak reference or an uncounted pointer
- a pointer that is set to 0 when the object
it points to is deallocated.

{And, um, yeah, I have code, although I would like
to bang on it for a while before submitting. If anyone
wants to test this really, really, rough code, ask, but
I would be too embarassed to submit it at this time.

Now, as I use it, I begin to see the need for
"live containers" - containers of live_pointers
that implicitly delete entries that are zero.

Again, I ask the list before coding, in case anyone has done the
like (as it appears folks had with live_ptrs/weak
references/uncounted pointers). If nothing else, y'all
might have advice as to how to code it.

E.g. a live_map: a map from address to a cached object,
    that automatically removes entries from the map when
    they are removed from the cache. Rather like an auxiliary
    index to a cache, always kept consistent as objects are removed
    from the cache.

    (I think that Reid will undestand this application).

"Automatic" removal of pointers to deallocated objects might be

a) instantaneous: the live_container might be registered
    the same way a live_pointer is, and have a method called
    on pointee deallocation

b) deferred: the live_container might contain live_pointers.
    When the live_container is queried, all entries containing 0
    live pointers would be removed.

    Typically this would be done inside an iterator:
            begin(), end(), ++, --, [], etc.

    As usual, I am lazy, and would prefer not to have to code up all of
    the iterator access methods - but I don't see anything like
    "iterator hooks".

    Count queries would be problematic: probably the stale objects
    should be removed from the container first.

    Overall, the complexity of this deferred implementation probably
    means that the instantaneous, registered, implementation is cleaner,
    even though the deferred implementation might be preferrable
    for performance.

Boost list run by bdawes at, gregod at, cpdaniel at, john at