From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 52836 invoked by alias); 2 Sep 2017 18:22:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 52825 invoked by uid 89); 2 Sep 2017 18:22:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=forgotten, learning X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 02 Sep 2017 18:21:56 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v82ILoEN032140 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 2 Sep 2017 14:21:54 -0400 Received: by simark.ca (Postfix, from userid 112) id EF8CA1EA26; Sat, 2 Sep 2017 14:21:49 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 7BB931E984; Sat, 2 Sep 2017 14:21:38 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 02 Sep 2017 18:22:00 -0000 From: Simon Marchi To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 3/3] Change counted_command_line to a shared_ptr In-Reply-To: <87y3px2l7p.fsf@tromey.com> References: <20170830220610.19718-1-tom@tromey.com> <20170830220610.19718-4-tom@tromey.com> <13f5b277e2bc200beafe7304791c32f5@polymtl.ca> <843aefc2fa977bad3d4b0e88dc0488de@polymtl.ca> <87y3px2l7p.fsf@tromey.com> Message-ID: <70aaf3656b19bb18b09c6f0bf4e7f500@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 2 Sep 2017 18:21:50 +0000 X-IsSubscribed: yes X-SW-Source: 2017-09/txt/msg00015.txt.bz2 On 2017-09-02 17:07, Tom Tromey wrote: > Simon> I looked at this more and found that free_command_lines was > indeed > Simon> being called when the shared_ptr free'd its pointer. I finally > Simon> understood that when assigning: > Simon> a_shared_ptr = a_unique_ptr; > Simon> like commands_command_1 does, for example, the deleter is also > Simon> transferred. > > Yeah, I should probably have mentioned that. I had to read about it > too, but then I think I had forgotten about it by the time I sent the > patch. I don't really understand why unique_ptr and shared_ptr differ > in this way; if you know the rationale I'd be interested in learning > it. From what I read, unique_ptr accepts its deleter as a template parameter so that it results in no overhead compared to a plain pointer. shared_ptr already has some overhead, so storing the deleter as a field of the control block isn't a big deal. It makes it more flexible, however. You can for example have a container of shared_ptr that have different deleters, which you can't do if the deleter is part of the type. https://stackoverflow.com/questions/27742290/deleter-type-in-unique-ptr-vs-shared-ptr This series LGTM. Simon