using boost::pool_allocator<T> ?
Hi,
I've experimenting with using boost::pool_allocator with std::vector and gcc
(4.1)., and I am having problems with segmentation violations. Below I give
a simple example of one way I am getting this
// Include files
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include "boost/pool/pool_alloc.hpp"
//--- Example main program
int main ( int argc, char** argv )
{
typedef std::vector< int, boost::pool_allocator<int> > Vector;
typedef std::map< int, Vector > Map;
Vector v;
v.push_back(10);
Map map;
map[2].push_back(10);
return 0;
}
gives
Program received signal SIGSEGV, Segmentation fault.
0x080497bc in boost::simple_segregated_storage<unsigned int>::segregate
(block=0x9d11098, sz=0, partition_sz=4,
end=0x9d111d0)
at /usr/include/boost/pool/simple_segregated_storage.hpp:207
207 nextof(iter) = old;
(gdb) where
#0 0x080497bc in boost::simple_segregated_storage<unsigned int>::segregate
(block=0x9d11098, sz=0,
partition_sz=4, end=0x9d111d0)
at /usr/include/boost/pool/simple_segregated_storage.hpp:207
#1 0x08049818 in boost::simple_segregated_storage<unsigned int>::add_block
(this=0x804d818, block=0x9d11098,
nsz=0, npartition_sz=4)
at /usr/include/boost/pool/simple_segregated_storage.hpp:72
#2 0x08049a36 in boost::simple_segregated_storage<unsigned
int>::add_ordered_block (this=0x804d818,
block=0x9d11098, nsz=0, npartition_sz=4)
at /usr/include/boost/pool/simple_segregated_storage.hpp:89
#3 0x08049aa4 in boost::simple_segregated_storage<unsigned
int>::ordered_free_n (this=0x804d818,
chunks=0x9d11098, n=0, partition_size=4)
at /usr/include/boost/pool/simple_segregated_storage.hpp:159
#4 0x08049b19 in
boost::pool<boost::default_user_allocator_new_delete>::ordered_free
(this=0x804d818,
chunks=0x9d11098, n=0) at /usr/include/boost/pool/pool.hpp:268
#5 0x0804a30d in boost::singleton_pool<boost::pool_allocator_tag, 4u,
boost::default_user_allocator_new_delete,
boost::details::pool::pthread_mutex, 32u>::ordered_free (ptr=0x9d11098,
n=0)
at /usr/include/boost/pool/singleton_pool.hpp:101
#6 0x0804a358 in boost::pool_allocator<int,
boost::default_user_allocator_new_delete,
boost::details::pool::pthread_mutex, 32u>::deallocate (ptr=0x9d11098, n=0)
at /usr/include/boost/pool/pool_alloc.hpp:107
#7 0x0804a378 in std::_Vector_base<int, boost::pool_allocator<int,
boost::default_user_allocator_new_delete,
boost::details::pool::pthread_mutex, 32u> >::_M_deallocate
(this=0xbffed858, __p=0x9d11098, __n=0)
at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_vector.h:133
#8 0x0804a3b0 in ~_Vector_base (this=0xbffed858)
at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_vector.h:119
#9 0x0804a3f4 in ~vector (this=0xbffed858)
at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_vector.h:272
#10 0x0804a436 in ~pair (this=0xbffed854)
at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_pair.h:69
#11 0x0804b040 in std::map<int, std::vector<int, boost::pool_allocator<int,
boost::default_user_allocator_new_delete,
boost::details::pool::pthread_mutex, 32u> >, std::less<int>,
std::allocator<std::pair<int const, std::vector<int,
boost::pool_allocator<int, boost::default_user_allocator_new_delete,
boost::details::pool::pthread_mutex, 32u> > > > >::operator[]
(this=0xbffed8ac, __k=@0xbffed8dc)
at /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:348
#12 0x08048cfd in main () at main.cpp:21
what I am doing wrong