Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost pool and move constructor
From: Bruno Sanches (bcsanches_at_[hidden])
Date: 2014-05-06 11:48:48


Nice! Thanks!

About the destroy, can I simple call myPool.destroy(obj) ?

Best Regards

Bruno Sanches
========================
http://www.pontov.com.br

On Tue, May 6, 2014 at 12:32 PM, Gabriel Redner <gredner_at_[hidden]> wrote:

> Hi Bruno,
>
> You can work around this problem by using malloc/free to manage the
> memory, and then creating and destroying the object yourself.
>
> void *mem = myPool.malloc();
> Object *obj = new (mem) Object(args);
>
> Then to destroy:
>
> obj->~Object();
> myPool.free(obj);
>
> -Gabe
>
>
> On Mon, May 5, 2014 at 11:10 PM, Bruno Sanches <bcsanches_at_[hidden]>wrote:
>
>> I am trying to create a object using boost object_pool, but trying to
>> use the move constructor of the desired object, but on Visual 2013, I am
>> always getting:
>>
>> error C2664: 'MyObject::MyObject(const MyObject &)' : cannot convert
>> argument 1 from 'MyObject (__cdecl &)(void)' to 'MyObject &&'
>>
>> The error happens because boost pool construct method always assume a
>> const parameter.
>>
>> Sample code:
>>
>>
>>
>> #include <boost/pool/object_pool.hpp>
>> class MyObject{
>> public:
>> MyObject():
>> m_iData(0)
>> {
>>
>> }
>>
>> MyObject(MyObject &&other):
>> m_iData(std::move(other.m_iData))
>> {
>> other.m_iData = 0;
>> }
>>
>> MyObject(const MyObject &rhs) = delete;
>>
>> MyObject &operator=(const MyObject &rhs) = delete;
>>
>> private:
>> int m_iData;};
>> int main(int, char**){
>> boost::object_pool<MyObject> pool;
>>
>> MyObject obj;
>>
>> MyObject *pObj = pool.construct(std::move(obj));}
>>
>> Is there any way to invoke the move constructor using boost::object_pool?
>>
>> Thanks
>> Bruno Sanches
>> ========================
>> http://www.pontov.com.br
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>
>
> _______________________________________________
> 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