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