By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

using boost::pool_allocator<T> ?

P: n/a
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_dele te>::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

Mar 25 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 25 Mar 2007 15:33:23 +0200, Chris Jones <jo****@hep.phy.cam.ac.uk
wrote:
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
It's a bug in boost::pool_allocator (you get also a crash with VC++ 8.0)..
See
http://sourceforge.net/tracker/index...86&atid=107586
for some details.

Boris
[...]
Mar 26 '07 #2

P: n/a
It's a bug in boost::pool_allocator (you get also a crash with VC++ 8.0).
See
http://sourceforge.net/tracker/index...86&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<intv1(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
Mar 27 '07 #3

P: n/a
On Tue, 27 Mar 2007 23:53:21 +0200, Chris Jones <jo****@hep.phy.cam.ac.uk>
wrote:
[...]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<intv1(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
Mar 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.