Boost logo

Boost Users :

Subject: Re: [Boost-users] Zero-malloc memory pool for Boost Intrusive smart pointers
From: Francesco (francesco.montorsi_at_[hidden])
Date: 2019-03-23 14:45:33


Hi Gavin,

Il giorno ven 22 mar 2019 alle ore 23:26 Gavin Lambert via Boost-users <
boost-users_at_[hidden]> ha scritto:

>
> Which brings up another point; your current
> implementation is not thread-safe. Which is
> fine, but you should probably mention that
> explicitly in your readme.

Actually that's mentioned already:
https://github.com/f18m/boost-intrusive-pool#about-thread-safety

> >My first implementation of the memory pool
> >indeed was using C++11 perfect forwarding to
> >call the ctor/dtor of type T when the item was
> >pulled out the pool or was returning to it.
> >I later removed such feature because I realized
> >that calling the ctor of the items to recycle
> >produced issues with classes having multiple inheritance IIRC.
> >I don't think it's safe and sane to call the
> >ctor of the same instance multiple times...Â
>
> Calls must be paired -- you allocate aligned
> uninitialised storage (aligned_storage), then
> placement-new to call the constructor on that
> storage, then eventually call the destructor, and
> then later you can placement-new again.
>
> You must never call the constructor twice in a
> row or the destructor twice in a row (unless it's
> trivial), but alternating is fine.
>
Again, this is how things like optional and
> variant work internally -- and since they do that
> part for you, it can be useful to re-use it
> rather than re-implementing it.
>

Interesting.
I remember I had some issues I could not figure out, but thanks for the
advice. I may retry this approach (perfect forwarding to the ctor) in the
future!

Thanks,
Francesco



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