[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] iconv made easy

From: Bruno Haible
Subject: Re: [bug-gnulib] iconv made easy
Date: Mon, 13 Dec 2004 22:00:45 +0100
User-agent: KMail/1.5

Paul Eggert wrote:
> > You will notice that there are two approaches to converting a string:
> > a) allocate an initial buffer and extend it as needed, stopping and
> >    restarting iconv() each time a realloc is needed,
> > b) call iconv() once to determine the length and then once again for
> >    filling the result string.
>   c) Use MB_LEN_MAX to calculate an upper bound for the size of the
>      output buffer (from the input buffer size).  Allocate a buffer of
>      that size, invoke iconv(), and then realloc the buffer once
>      iconv() finishes and you know the correct size.

MB_LEN_MAX is not usable, see your quotearg.c commit from 2000-07-23, and
also because some iconv conversions need up to 12 bytes per character,
whereas on glibc systems MB_LEN_MAX = 6.

But certainly approach (a) gets more speed if the initial buffer is so large
that with a high probability, no stopping-resizing-restarting is needed.

Given the intricacies of the forward/backward games played in
glibc/iconv/skeleton.c, I cannot give an estimate how large this buffer
must be made such that (a) outperforms (b).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]