Bugtraq mailing list archives
the purpose of dynamic memory allocation
From: djb () CR YP TO (D. J. Bernstein)
Date: Thu, 5 Mar 1998 01:08:31 -0000
Sorry to drag out this thread, but there's a fundamental misconception here, the source of a tremendous amount of bad programming:
Certain things have well defined limits. Filename, pathnames, etc. There is no need to use dynamic memory for them.
You're missing the point. Dynamic allocation _saves_ memory. If you've set aside a 4096-byte static buffer for a line of text that's only 60 bytes long, for example, then you're wasting four thousand bytes of memory. Do the same thing in fifty different functions, in ten running programs, and suddenly you've wasted two megabytes of memory. Poor engineering. Ever wonder why your system is swapping? It is much better to give those 2 megabytes back to the user. That's exactly what dynamic allocation does: your program grabs only as much memory as it needs. A side benefit of dynamic allocation is that it's very easy to manage. There's just one number to select---the size of one central buffer--- instead of an incomprehensible 8192 here and 1000 there and so on. Of course, this was all figured out years ago. The UNIX kernel provides a centralized mechanism to let programs dynamically allocate memory, up to a limit assigned by the sysadmin. For further discussion of modern UNIX resource management, see http://pobox.com/~djb/docs/resources.html. As for Venema's ``discovery'' (gee, he read the qmail documentation!), see http://pobox.com/~djb/qmail/venema.html. ---Dan Smaller, faster, safer than inetd+tcpd. http://pobox.com/~djb/ucspi-tcp.html
Current thread:
- the purpose of dynamic memory allocation D. J. Bernstein (Mar 04)
- Re: the purpose of dynamic memory allocation sinster () DARKWATER COM (Mar 05)
- New OpenBSD security web page Theo de Raadt (Mar 06)
- <Possible follow-ups>
- Re: the purpose of dynamic memory allocation tqbf () secnet com (Mar 06)
- Possible Bug in CDE on HP-UX gareth greenaway (Mar 09)
- Re: Possible Bug in CDE on HP-UX Jeremy Brinkley (Mar 10)
- Re: the purpose of dynamic memory allocation David LeBlanc (Mar 10)
- Re: the purpose of dynamic memory allocation Jeffrey Hutzelman (Mar 10)
- Re: the purpose of dynamic memory allocation Alan Cox (Mar 11)
- DoS (and possibly more) on MDaemon for NT/95 Alvaro Martinez Echevarria (Mar 10)
- MDaemon SMTP Server Buffer Overflow's Aleph One (Mar 10)
- Possible Bug in CDE on HP-UX gareth greenaway (Mar 09)