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


>>>>> "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.

Tom


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