Re: [RFA 14/22] Replace two xmallocs with vector

Pedro Alves
2016-10-09T17:20:50Z

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