|
Boost Users : |
Subject: Re: [Boost-users] [Pool] Use singleton_pool in struct
From: Piotr Kowalski (koval.gnu_at_[hidden])
Date: 2012-10-12 04:12:43
I am just guessing, as I have never used singleton_pool
It looks like malloc() returns raw memory. You just cast the raw pointer to
data*
Since 'data' is a non-POD type it should be initialized by calling the
constructor
I would suggest changing the call to
data* d = new(myStruct::poolMemory::malloc()) data();
This placement new syntax results in calling the constructor on the raw
address obtained from malloc()
The default constructor will initialize "myComplexType" and make it usable
Hope that helps
2012/10/12 Claude <clros_at_[hidden]>
> Ok, now it work well, thanks!
>
> But..I have another problem. In this code (C++11 with std::tuple)
>
> #include <iostream>
> #include <map>
> #include <tuple>
> #include <boost/pool/pool_alloc.hpp>
>
> using namespace std;
>
> struct data
> {
> int a,b;
> char name[50];
> std::map<std::string,std::tuple<uint16_t,uint16_t>> myComplexType;
> };
>
> struct myStruct
> {
> struct MyOrderTag {};
> typedef boost::singleton_pool<MyOrderTag,sizeof(data)> poolMemory;
> };
>
>
> int main()
> {
> data *d = (data*)myStruct::poolMemory::malloc();
>
> d->a = 8;
> strcpy(d->name,"Hello!");
>
> //fill myComplexType field (this row causes a segfault!)
> d->myComplexType["one"] = std::tuple<uint16_t,uint16_t>(1,2);
>
>
> myStruct::poolMemory::release_memory();
> return 0;
> }
>
> I obtain a segmentation fault error when assign a tuple at myComplexType
> field. What is wrong?
>
>
>
>
> --
> View this message in context:
> http://boost.2283326.n4.nabble.com/Pool-Use-singleton-pool-in-struct-tp4636741p4637005.html
> Sent from the Boost - Users mailing list archive at Nabble.com.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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