This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 3/3] Change counted_command_line to a shared_ptr


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]