Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2007-01-25 16:26:41


AMDG

Michael Marcin wrote:
> Well I tried it out, seemed to work fine except for the original problem.
>
> I added one extra function to the object_pool class:
>
> void destroy( const iterator& it )
> {
> destroy( static_cast<T*>(static_cast<void*>(it.i)) );
> }
>
> And then invoked my DestroyAll function with some items allocated from
> the pool which looks like:
>
> boost::object_pool<Object>::iterator it = m_object_pool.begin();
> while( it != m_object_pool.end() )
> {
> m_object_pool.destroy( it++ );
> }
>
> The second iteration loops infinitely inside of
>
> template <typename SizeType>
> void * simple_segregated_storage<SizeType>::find_prev(void * const ptr);
>
> Not quite sure why.
>
> Thanks,
>
> Michael Marcin

I made a mistake. See if these work.

    class iterator {
        //...
        iterator& operator++() {
            while(true) {
                i += increment;
                if(i == end) {
                    iter = iter.next();
                    if(iter.valid()) {
                        i = iter.begin();
                        end = iter.end();
                        if(i != freed_iter) {
                            break;
                        }
                    } else {
                        i = 0;
                        break;
                    }
                }
                if(i != freed_iter) break;
                freed_iter = object_pool<T,
UserAllocator>::nextof(freed_iter);
            }
            return(*this);
        }
    };

    iterator begin() {
        iterator result;
        if(this->list.valid()) {
            result.increment = this->alloc_size();
            result.iter = this->list;
            result.freed_iter = this->first;
            result.i = this->list.begin();
            result.end = this->list.end();
            if(result.freed_iter == result.i) {
                result.freed_iter = object_pool<T,
UserAllocator>::nextof(result.freed_iter);
                ++result;
            }
        } else {
            result.i = 0;
        }
        return(result);
    }

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk