This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH:MI] Return a subset of a variable object's children
- From: Vladimir Prus <vladimir at codesourcery dot com>
- To: "Marc Khouzam" <marc dot khouzam at ericsson dot com>
- Cc: "Nick Roberts" <nickrob at snap dot net dot nz>, gdb-patches at sources dot redhat dot com
- Date: Thu, 1 May 2008 19:55:54 +0400
- Subject: Re: [PATCH:MI] Return a subset of a variable object's children
- References: <6D19CA8D71C89C43A057926FE0D4ADAA042910B7@ecamlmw720.eamcs.ericsson.se>
On Wednesday 30 April 2008 18:21:03 Marc Khouzam wrote:
> > > > > > but only actually create the children that have been requested by the
> > > > > > user. I'm not sure how much efficiency there is by allocating the
> > > > > > memory before hand? Also, is there no way to grow the vector by more
> > > > > > than a single point at a time?
> > > > >
> > > > > Like resize with STL vectors? I'm not aware of one.
> > > >
> > > > VEC_safe_grow
> > >
> > > OK, I didn't know about that. Why not use it instead of VEC_safe_push in the
> > > construct above?
> >
> > Well, it happens not to initialize the data, so some changes in further logic will
> > be required. Until now, it was not a performance issue.
>
> My concern about
>
> while (VEC_length (varobj_p, var->children) < var->num_children)
> VEC_safe_push (varobj_p, var->children, NULL);
>
> is that the vector may be reallocated multiple times.
As soon as we're into big-O here, we still get amortized linear time.
> How about something like this (assuming quick_push does what I think it does)
>
> var->children = VEC_alloc(varobj_p, var->num_children);
> for (i=0; i<var->num_children; i++)
> VEC_quick_push (varobj_p, var->children, NULL);
>
> Same loop, but it avoids having to reallocate the vector.
Yes, it's a bit more efficient.
- Volodya