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: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tom at tromey dot com>, gdb-patches at sourceware dot org
- Date: Sun, 9 Oct 2016 18:20:36 +0100
- 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>
On 09/27/2016 05:08 AM, Tom Tromey wrote:
> This replaces a couple of uses of xmalloc with a std::vector, also
> removing a couple of cleanups.
>
> 2016-09-26 Tom Tromey <tom@tromey.com>
>
> * cli/cli-dump.c (dump_memory_to_file): Use std::vector.
> (restore_binary_file): Likewise.
As general guideline, for these cases where we only need to
construct a buffer once (never resize/reallocate) and we don't
care about the initial contents of the buffer, I think
unique_ptr<char[]> buf (new char[size]);
ends up being more efficient, because std::vector
default/zero initializes its elements, which is unnecessary since
we're about to write into the buffer anyway.
WDYT?
(I'll try to post my unique_ptr shim soon.)
Thanks,
Pedro Alves