of course!

Dan Bernstein brnstnd at stealth.acf.nyu.edu
Thu Nov 23 16:05:00 AEST 1989


In article <1051 at root44.co.uk> gwc at root.co.uk (Geoff Clare) writes:
> In article <17303 at rpp386.cactus.org> jfh at rpp386.cactus.org (John F. Haugh II) writes:
> >		char dir[PATH_MAX];
> >		strcpy(dir, path);
> >             strcat(dir, "/.");
> Anyway,
> using a maximum length array is rather wasteful - malloc(strlen(path)+3)
> would be much better all round.

Ummm, no. PATH_MAX is much smaller than the page size on most machines,
so it almost certainly won't change the actual memory use of the process.
In contrast, malloc(strlen()) is noticeably slower, a bit less readable,
and prone to failure.

Unless a lot of memory is tied up in such arrays, malloc() isn't worth
it. Don't waste dynamic memory for static uses.

Followups to comp.lang.c so I don't have to read them.

---Dan



More information about the Comp.unix.wizards mailing list