C++ Logo

std-proposals

Advanced search

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

From: Greg McPherran <GMcPherran_at_[hidden]>
Date: Mon, 15 Aug 2022 00:05:37 +0000
>> common operation
unique_ptr::reset()

... as I mentioned in my original request/suggestion.

Basically any collection (e.g. vector) scenario where one would
dynamically delete objects and create new ones of the same class. Useful
for object pool scenarios. That reminds me that I also request a class
"pool" keyword or similar that automatically uses an object pool for
instances of the class.

I propose that many applications exist today that are dynamically
delete-ing and new-ing objects of the same class. 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++.

Greg McPherran

------ Original Message ------
>From "Henry Miller via Std-Proposals" <std-proposals_at_[hidden]>
To "Henry Miller via Std-Proposals" <std-proposals_at_[hidden]>
Cc "Henry Miller" <hank_at_[hidden]>
Date 2022-08-14 7:39:12 PM
Subject Re: [std-proposals] Class Instance Re-Use/Re-Init

>A language feature is only better if this is a common operation, otherwise it is syntax to ban in my code style document. This is not something i've ever needed which makes me suspect it is a rare situation. Prove that this is a common operation on some well written code and I'll reconsider.
>Note that I specified well written there are a lot of frameworks that require weird things that we now agree are wrong. If you point to one of them we will respond switch to a better framework.
>
>-- Henry Miller
>hank_at_[hidden]
>
>On Sun, Aug 14, 2022, at 16:17, Greg McPherran via Std-Proposals wrote:
>>Hi,
>>
>>Great workaround suggestions by some, but the existence of these workarounds proves my point that a language feature is superior. One can also accomplish OO-like behavior in C without C++, but the syntax of C++ is superior. Before C++ existed and a C programmer suggested classes and objects as a feature, once could argue "you don't need that, you can use function pointers in structs". Yes, "workarounds" exist but the whole point of language syntax is to incorporate it into the more simple and concise patterns of the language usage.
>>
>>By the way, along with this feature, I also request a related feature for "const after init once". This related feature would be very helpful for objects that are conceptually intended to be global constants but one would like the chance the initialize them once (and only once) at runtime (typically in early startup time). So they are automatically const after they are initialized the first time.
>>
>>So, in summary, the two features that I am requesting as a C++ customer are:
>>Ctor-like re-init once-and-done special functions that are not available as normal functions after init just as ctor is not available as a normal function on an object.
>>const after first init
>>Thank You,
>>Greg McPherran
>>-- Std-Proposals mailing list
>>Std-Proposals_at_[hidden]
>>https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>-- Std-Proposals mailing list
>Std-Proposals_at_[hidden]
>https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-08-15 00:05:40