C++ Logo


Advanced search

Re: [std-proposals] Class Instance Re-Use/Re-Init

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 14 Aug 2022 20:54:02 -0400
On Sun, Aug 14, 2022 at 8:05 PM Greg McPherran via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> >> common operation
> unique_ptr::reset()
> ... as I mentioned in my original request/suggestion.

That a class has a function does not mean that this concept is
"common". Also, it's not clear how this works for any object.
`unique_ptr::reset` is built on specific information about the object
type itself.

> Basically any collection (e.g. vector) scenario where one would dynamically delete objects and create new ones of the same class.

I don't think the construction and destruction of the object (which is
the only thing your suggestion actually involves) is the slow part of
this process. It's the memory allocation.

> Useful for object pool scenarios.

Case in point: "object pools" are about where the storage for an
object comes from, not how it gets constructed or destructed.

> That reminds me that I also request a class "pool" keyword or similar that automatically uses an object pool for instances of the class.

Um, no.

> I propose that many applications exist today that are dynamically delete-ing and new-ing objects of the same class.

And my experience is that the deletion and allocation generally happen
in completely different places in the code, such that
intercommunication is not something that can be handled automatically
without having a garbage collector.

> The performance impact of not simply re-using the same memory is absurd. Java and C# have garbage collectors. Better to recycle the garbage in C++.

Received on 2022-08-15 00:54:26