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@tiscali.it>
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&lt;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@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users