Custom (pool) allocator with boost shared_ptr

前端 未结 3 1194
灰色年华
灰色年华 2021-01-31 09:20

I want objects managed by a shared_ptr to be allocated from a pool, say Boost\'s Pool interface, how can this be achieved?

3条回答
  •  眼角桃花
    2021-01-31 10:08

    Evident solution:

    Create your own make_shared function and enforce the use of this method to created shared_ptr. Those who derive from The Rule shall be punished.

    Note:

    There seems to be a confusion with the role of the shared_ptr. Its role is to manage memory than YOU have allocated, however to do so it requires some allocation of its own (counter and deleter), thus you may pass it an allocator for those.

提交回复
热议问题