Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA 3/3] Change counted_command_line to a shared_ptr
Date: Sat, 02 Sep 2017 18:22:00 -0000	[thread overview]
Message-ID: <70aaf3656b19bb18b09c6f0bf4e7f500@polymtl.ca> (raw)
In-Reply-To: <87y3px2l7p.fsf@tromey.com>

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


  reply	other threads:[~2017-09-02 18:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30 22:06 [RFA 0/3] some C++-ification in breakpoint.c Tom Tromey
2017-08-30 22:06 ` [RFA 2/3] Use function_view in a couple of places " Tom Tromey
2017-08-30 22:06 ` [RFA 3/3] Change counted_command_line to a shared_ptr Tom Tromey
2017-09-01 20:48   ` Simon Marchi
2017-09-02 10:48     ` Simon Marchi
2017-09-02 15:31       ` Tom Tromey
2017-09-02 18:22         ` Simon Marchi [this message]
2017-09-21  3:52           ` Tom Tromey
2017-08-30 22:06 ` [RFA 1/3] Allocate bpstats with new Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=70aaf3656b19bb18b09c6f0bf4e7f500@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox