This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA 14/22] Replace two xmallocs with vector
- From: Trevor Saunders <tbsaunde at tbsaunde dot org>
- To: Tom Tromey <tom at tromey dot com>
- Cc: Pedro Alves <palves at redhat dot com>, gdb-patches at sourceware dot org
- Date: Thu, 13 Oct 2016 11:35:24 -0400
- Subject: Re: [RFA 14/22] Replace two xmallocs with vector
- Authentication-results: sourceware.org; auth=none
- References: <1474949330-4307-1-git-send-email-tom@tromey.com> <1474949330-4307-15-git-send-email-tom@tromey.com> <2bb436df-b6ee-cc2f-c4c1-1a79d6fcdce1@redhat.com> <87oa2oxpy6.fsf@tromey.com>
On Thu, Oct 13, 2016 at 08:51:13AM -0600, Tom Tromey wrote:
> >>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> As general guideline, for these cases where we only need to
> Pedro> construct a buffer once (never resize/reallocate) and we don't
> Pedro> care about the initial contents of the buffer, I think
> Pedro> unique_ptr<char[]> buf (new char[size]);
> Pedro> ends up being more efficient, because std::vector
> Pedro> default/zero initializes its elements, which is unnecessary since
> Pedro> we're about to write into the buffer anyway.
>
> I made this change in my patches.
>
> While doing so I realized one reason to prefer vector: with vector you
> can build gdb with the libstdc++ debug mode, and get range checking.
On the other hand if there isn't already a debug unique_ptr with the same
checking it seems like we should add that. It shouldn't be terribly
hard.
Trev
>
> Tom