Boost Pool - error: segmentation fault

Hi All, I am trying to use the Boost Pool library, more specifically I am trying to use the singleton pool interface. Everything seems to work fine, till the moment I use it to create an object from a class containing a (STL) map, which results in a segmentation fault. Does anyone know why this happens, or how to work around it? What I find also strange is that the constructor and destructor of the class doesn't seem to be called when using the pool. Is this normal behavior? Please find below the example that causes the segmentation fault (and the not calling of the constructor/destructor issue). Thanks a lot in advance. Kind regards, Joost ========================================== class MyClass { public: int x; vector y; map z; }; int main() { typedef boost::singleton_pool myPool; MyClass * const t = (MyClass *) myPool::malloc(); t->x = 1; t->y.push_back(2); t->z.insert(make_pair(3,3));//causes segmentation fault myPool::purge_memory(); } ========================================== _________________________________________________________________ Probeer Live Search: de zoekmachine van de makers van MSN! http://www.live.com/?searchOnly=true

Joost Meijles wrote:
Hi All,
I am trying to use the Boost Pool library, more specifically I am trying to use the singleton pool interface. Everything seems to work fine, till the moment I use it to create an object from a class containing a (STL) map, which results in a segmentation fault. Does anyone know why this happens, or how to work around it?
What I find also strange is that the constructor and destructor of the class doesn't seem to be called when using the pool. Is this normal behavior?
Please find below the example that causes the segmentation fault (and the not calling of the constructor/destructor issue).
Pool traffics in raw memory, not objects, you need to construct the object inplace and destroy it yourself, or else use object_pool. HTH, John.

AMDG Joost Meijles wrote:
Hi All,
I am trying to use the Boost Pool library, more specifically I am trying to use the singleton pool interface. Everything seems to work fine, till the moment I use it to create an object from a class containing a (STL) map, which results in a segmentation fault. Does anyone know why this happens, or how to work around it?
What I find also strange is that the constructor and destructor of the class doesn't seem to be called when using the pool. Is this normal behavior?
Yes.
myPool::malloc does not initialize the MyClass.
You need to do so explicitly.
#include <vector>
#include <map>
#include

Thanks a lot. The object_pool approach doesn't work; it causes also a segmentation fault. The option of explicitly allocating the object does work fine. Regards, Joost ----------------------------------------
Date: Tue, 25 Mar 2008 09:28:16 -0700 To: boost-users@lists.boost.org From: watanabesj@gmail.com Subject: Re: [Boost-users] Boost Pool - error: segmentation fault
AMDG
Joost Meijles wrote:
Hi All,
I am trying to use the Boost Pool library, more specifically I am trying to use the singleton pool interface. Everything seems to work fine, till the moment I use it to create an object from a class containing a (STL) map, which results in a segmentation fault. Does anyone know why this happens, or how to work around it?
What I find also strange is that the constructor and destructor of the class doesn't seem to be called when using the pool. Is this normal behavior?
Yes.
myPool::malloc does not initialize the MyClass. You need to do so explicitly.
#include #include #include
using namespace std;
class MyClass { public: int x; vector y; map z; };
int main() { typedef boost::singleton_pool myPool;
MyClass * const t = (MyClass *) myPool::malloc(); new(t) MyClass; t->x = 1; t->y.push_back(2); t->z.insert(make_pair(3,3));//causes segmentation fault
t->~MyClass();
myPool::purge_memory(); }
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_________________________________________________________________ Download Messenger op je mobiel! http://www.windowslivemobile.msn.com/nl/

Thanks a lot. The object_pool approach doesn't work; it causes also a segmentation fault. The option of explicitly allocating the object does work fine.
Make sure you use a recent compiler and Boost. I have seen pool
segfaulting on some not-so-old platforms, especially with pool_allocator
being used with nested containers. I found out that with Boost 1.34.1,
g++ 4.3.0 and MSVC 9.0 all works fine.
For example the following segfaults with g++ 4.2.2 + boost 1.32:
#include

Thanks a lot. The object_pool approach doesn't work; it causes also a segmentation fault. The option of explicitly allocating the object does work fine.
Make sure you use a recent compiler and Boost. I have seen pool segfaulting on some not-so-old platforms, especially with pool_allocator being used with nested containers. I found out that with Boost 1.34.1, g++ 4.3.0 and MSVC 9.0 all works fine.
I've looked into the pool.hpp commitlog and it seems that the error I mentioned ("vector of vectors" or similar usage) was fixed 2005-1-19, so it probably never was a compiler issue. Filip
participants (4)
-
Filip Konvička
-
John Maddock
-
Joost Meijles
-
Steven Watanabe