On 15/01/2017 23:53, Stefan Ram wrote:
> JiiPee <
n...@notvalid.com> writes:
>> But if for some reason you want to use raw pointers, then just loop the
>> array and use "delete" to delete each object:
> If one wants raw pointers, one still can often get by
> without new and delete. One just emplaces the new T objects
> to the end of a vector< T >, and then one can take the
> address of the new T entry (and possibly then append that
> to the end of another vector of raw pointers).
>
> Optimization: When individual entries should be deleted
> before the whole array is deleted, their destructor can
> be called and then their address can be added to a free
> list. Now, when a new T needs to be added, we will first
> check the free list and then possibly use a placement new.
>
> For many cases, not all, this will suffice.
>
But this is more work and in many cases there is no need to optimize
like this. I like the idea of unique pointer as it makes it easy... dont