473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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_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
3 6379
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Barry | last post by:
As boost::pool_alloc use singleton holder for pool allocator, client programmers have to reclaim the memory by hand through calling singleton_pool<alloc_tag, elem_size>::purge_memory() or something...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.