[PATCH 2/3] gdb: use std::vector to store segments in symfile_segment_data

Simon Marchi simon.marchi@efficios.com
Tue May 19 14:52:19 GMT 2020


On 2020-05-19 10:55 a.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon>    symfile_segment_data_up data (new symfile_segment_data);
> Simon> -  data->num_segments = num_segments;
> Simon> -  data->segment_bases = XCNEWVEC (CORE_ADDR, num_segments);
> Simon> -  data->segment_sizes = XCNEWVEC (CORE_ADDR, num_segments);
> 
> Simon>    for (i = 0; i < num_segments; i++)
> Simon> -    {
> Simon> -      data->segment_bases[i] = segments[i]->p_vaddr;
> Simon> -      data->segment_sizes[i] = segments[i]->p_memsz;
> Simon> -    }
> Simon> +    data->segments.emplace_back (segments[i]->p_vaddr, segments[i]->p_memsz);
> 
> It's probably better to just resize() to the desired size, instead of
> using emplace_back.  That may save some memory, because it won't
> over-allocate.
> 
> Probably not super important, but at the same time easy to do.

Good point, will do.  I probably can't resize if the elements are not
default constructible, but if I call reserve, it should work as well?

Simon


More information about the Gdb-patches mailing list