|
Boost Users : |
From: Joost Meijles (joostmeijles_at_[hidden])
Date: 2008-03-26 04:28:57
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_at_[hidden]
> From: watanabesj_at_[hidden]
> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
_________________________________________________________________
Download Messenger op je mobiel!
http://www.windowslivemobile.msn.com/nl/
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net