Re: [dev] sbase TODO patch
On Thu, Feb 09, 2012 at 04:06:59PM -0500, Galos, David wrote:
> malloc() in yes(1) is definitely overkill. I've attached a simple
> version.
Invoking malloc() once (resulting in O(1) additional time and space) is
overkill but using printf() in every iteration (which means firing up
the printf() parser over and over again) isn't? I think you're a tad off
base, sir...
There's only two ways to implement this properly:
* Build the string during program initialization and use puts() (or
something similar) to print that string over and over again.
* Call the output routine once for each token in each iteration. If we
use buffered streams, this shouldn't make much difference. We should
probably do some quick performance tests to be sure, though.
> #include <stdio.h>
>
> int
> main(int argc, char **argv)
> {
> const char *y[] = {"","y"};
> int i;
>
> if(argc < 2)
> argv=y, argc=2;
>
> for(;;){
> for(i=1; i<argc; i++)
> printf("%s%s\n", argv[i], (i==argc-1)?"":" ");
> }
> }
Received on Thu Feb 09 2012 - 22:37:51 CET
This archive was generated by hypermail 2.3.0
: Thu Feb 09 2012 - 22:48:04 CET