using boost::pool_allocator<T> ?

C

Chris Jones

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>::eek:rdered_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>::eek:rdered_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>::eek:rdered_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> > > > >::eek:perator[]
(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
 
C

Chris Jones

It's a bug in boost::pool_allocator (you get also a crash with VC++ 8.0).
See
http://sourceforge.net/tracker/index.php?func=detail&aid=1179641&group_id=7586&atid=107586
for some details.

Boris

Hi,

Thanks for your reply. I guess I will just have to work around thins
problem. Judging by the post dates, the bug has been around for some time.
Any idea if a fix is coming or not ?

FYI I've discover that the other reason I was getting segmentation
violations was due to requests for vectors of size 0. i.e.

std::vector<int> v1(0); // works fine
std::vector<int,boost::pool_allocator<int> > v2(0); // causes a segmentation
violation when v2 goes out of scope.

same problem ?

cheers Chris
 
B

Boris

[...]Thanks for your reply. I guess I will just have to work around thins
problem. Judging by the post dates, the bug has been around for some

Yes, you have to remove pool_allocator from the inner vector.
time.
Any idea if a fix is coming or not ?

I don't know. I think there hasn't been anyone working on this problem so
far.
FYI I've discover that the other reason I was getting segmentation
violations was due to requests for vectors of size 0. i.e.

std::vector<int> v1(0); // works fine
std::vector<int,boost::pool_allocator<int> > v2(0); // causes a
segmentation
violation when v2 goes out of scope.

same problem ?

Hm, don't know really. If you want to be sure you better submit another
bug report. :)

Boris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top