Global “placement” delete[]

后端 未结 4 1741
北恋
北恋 2021-02-06 03:19

I am trying to replace new/delete with my own allocator(s). So, overriding placement new and delete - quite happy with that. Looks something like this ...

void*          


        
4条回答
  •  时光取名叫无心
    2021-02-06 03:45

    When in doubt go to the expert:

    http://www.stroustrup.com/bs_faq2.html#placement-delete

    But how can we later delete those objects correctly? The reason that there is no built-in "placement delete" to match placement new is that there is no general way of assuring that it would be used correctly. Nothing in the C++ type system allows us to deduce that p1 points to an object allocated in Arena a1. A pointer to any X allocated anywhere can be assigned to p1.

    The rest of the link goes onto describe how to remedy the situation.

提交回复
热议问题