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 14/22] Replace two xmallocs with vector


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


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