C++ Logo

std-proposals

Advanced search

Re: [std-proposals] 回复: Relocating destructor and operator reloc

From: 李 秋逸 <QiuyiLi1023_at_[hidden]>
Date: Fri, 28 Jun 2024 17:03:34 +0000
This is a very long lived problem in C++ and many proposals have talked about it. For example, we have a vector of std::unique_ptr, then we know that they are just wrapped pointer. In fact, we can just use a memcpy to relocate these pointers to the new memory and just skip the destructor. But how to tell it to the complier?
________________________________
发件人: Std-Proposals <std-proposals-bounces_at_[hidden]> 代表 Nikolay Mihaylov via Std-Proposals <std-proposals_at_[hidden]>
发送时间: 星期六, 六月 29, 2024 12:51:00 上午
收件人: Std-Proposals <std-proposals_at_[hidden]>
抄送: Nikolay Mihaylov <nmmm_at_[hidden]>
主题: Re: [std-proposals] 回复: Relocating destructor and operator reloc

I did not follow the emails but isnt this the same as move c-tor? It can also be used to reallocate the object to new address.

On Fri, Jun 28, 2024, 19:43 F. v.S. via Std-Proposals <std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>> wrote:
I totally disagree on that this can be an easy and flexible way. But I'd hear what other guys say.

It seems to me that when the new relocating "destructor" is not defaulted, the identity (or the address) of the returned object (i.e. the destination of relocation) ALMOST ALWAYS needs to be known in the function body. So it'll be simpler, at least to me, to invent a new way to directly refer to the destination object, instead of finding how to guarantee NRVO.

Thanks,
F.v.S.
________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]<mailto:std-proposals-bounces_at_[hidden]>> on behalf of 李 秋逸 via Std-Proposals <std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>>
Sent: Saturday, June 29, 2024 0:31
To: std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]> <std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>>
Cc: 李 秋逸 <QiuyiLi1023_at_[hidden]<mailto:QiuyiLi1023_at_[hidden]>>
Subject: [std-proposals] Relocating destructor and operator reloc

Sorry for bother you. Seeing some proposals about relocating in C++, I think I found a easy and flexible way to do this with least changes to the core feature of C++ language. You can check it in the attachment or click https://github.com/YandereChan2/Relocating-destructor-and-operator-reloc/blob/main/Operator%20reloc%20and%20relocating%20destructor.md .

The core idea is introduce a new destructor T ~T(int), and with the help of RVO/NRVO to relocate an object from one address to the address of the return value.
--
Std-Proposals mailing list
Std-Proposals_at_lists.isocpp.org<mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-06-28 17:03:41