Boost logo

Boost :

From: Greg Rosenblatt (glr9940_at_[hidden])
Date: 2005-04-07 18:12:10


While debugging some recent changes to a program I'm working on, I
discovered that pool_allocators seem to break when a vector using the
allocator is contained within another vector.

The problem disappears when the standard allocator is used instead.
I'm including a small test program that illustrates the problem. The
program causes a segmentation fault on my computer with GCC 3.3 and a
friend's computer with GCC 3.4. Am I using the pool library
incorrectly, or is there a real issue here? I really like the
concepts behind this library, and I'd like to continue using it.

This is also my first time posting to this mailing group, so if I've
made any mistakes in this post, please let me know so I can correct
them.

Thanks in advance,
Greg

Source:
Note that switching the definition of EventVector will fix the problem.
Also note that the definition of IndexVector doesn't seem to matter.

#include <boost/pool/pool_alloc.hpp>
#include <vector>
#include <iostream>

template <typename DataType>
struct PooledVector {
        typedef std::vector<DataType
                                        ,boost::pool_allocator<DataType> > Type;
};

typedef PooledVector<int>::Type EventVector;
//typedef std::vector<int> EventVector;

//typedef PooledVector<EventVector>::Type IndexVector;
typedef std::vector<EventVector> IndexVector;

int main() {
        try {
                std::cout << sizeof(EventVector) << " " << sizeof(IndexVector) << "\n";
                IndexVector iv;
                iv.push_back(EventVector());
                iv.back().push_back(3);
                std::cout << "it works\n";
        }
        catch (...) {
                std::cout << "exception\n";
        }
        return 0;
}


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