How to prevent destructors from being called on objects managed by boost::fast_pool_allocator?

后端 未结 3 583
伪装坚强ぢ
伪装坚强ぢ 2021-01-06 09:33

I would like to take advantage of the following advertised feature of boost::fast_pool_allocator (see the Boost documentation for Boost Pool):

3条回答
  •  不要未来只要你来
    2021-01-06 10:09

    By default pool uses the default_user_allocator_new_delete allocator. This will destroy underlying objects by calling the destructor first and then reclaiming underlying memory. The default_user_allocator_malloc_free will cause malloc'ed memory to be reclaimed without firing the destructor - hence drop[ing] them off into oblivion.

    That said, if your tree is really that complicated, using free instead of firing destructors seems like a really good way to start chopping branches out from under yourself and potentially start leaking memory you can no longer reach.

提交回复
热议问题