bug-gnulib
[Top][All Lists]
Advanced

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

Re: xctime()


From: Bruno Haible
Subject: Re: xctime()
Date: Tue, 26 Jan 2010 23:09:36 +0100
User-agent: KMail/1.9.9

Robert Millan wrote:
> Ok then.  But if I preallocate a buffer on the stack, then xctime() can't
> return it.

Of course it cannot return a pointer to an array in its own stack frame.

You want to write a function that executes strftime and returns its result
in freshly allocated memory. You can assume that
  - 1 strftime call is pretty expensive, say, costs 100 units.
  - 1 malloc or realloc call is pretty cheap, say, costs 5 units,
  - copying memory around is very cheap, costs, say, 1 unit. (*)
You know that 99% of the time, the result will be less than 1024 bytes
long.

How do you write the function so that it minimizes the cost in the average
case?

Bruno


(*) These figures are only indicative. I haven't measured it concretely.




reply via email to

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