Re: [PATCH:MI] Return a subset of a variable object's children

Vladimir Prus
2008-05-01T15:56:13Z

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