[Ltrace-devel] [RFC 1/5] vect: Fix vect_reserve for large count

Edgar E. Iglesias edgar.iglesias at gmail.com
Fri Oct 5 18:29:50 UTC 2012


Sorry for the bad formatting im on phone.

The issue is that if count is large enough, na might not end up as count
triggering the assert. We can keep the exponential growth with another fix.
I didnt realize that was important here.

Thanks

---
Sent from my phone
On Oct 5, 2012 6:38 PM, "Petr Machata" <pmachata at redhat.com> wrote:

> edgar.iglesias at gmail.com writes:
>
> >  vect_reserve(struct vect *vec, size_t count)
> >  {
> >       if (count > vec->allocated) {
> > -             size_t na = vec->allocated != 0 ? 2 * vec->allocated : 4;
> > +             /* Allocate 4 extra slots for growth.  */
> > +             size_t na = count + 4;
> >               void *n = realloc(vec->data, na * vec->elt_size);
> >               if (n == NULL)
> >                       return -1;
>
> That changes performance characteristics of vect_pushback from O(1) to
> O(n).  What problem are you seeing that is fixed by this?
>
> If we are that memory-tight, perhaps we could have a call like
> vect_done, which would allocate a new buffer with exact number of slots,
> copy stuff there, and release the old buffer (or keep it around for next
> vect_init?).  Or there could be a separate ctor taking slot count as an
> argument, which we would use to pre-allocate things like value arrays,
> where we have a guess on the number of elements.  It depends on what
> problem you are trying to solve.
>
> Thanks,
> PM
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/ltrace-devel/attachments/20121005/44185e1c/attachment.html>


More information about the Ltrace-devel mailing list