Bugtraq mailing list archives
Re: the purpose of dynamic memory allocation
From: sinster () DARKWATER COM (sinster () DARKWATER COM)
Date: Thu, 5 Mar 1998 14:21:36 -0800
Sprach "D. J. Bernstein" <djb () CR YP TO>: [...]
You're missing the point. Dynamic allocation _saves_ memory.
[...] Dynamic allocation only saves memory when your program executes for a short period of time, or your program uses memory in such a way that memory fragmentation is a non issue (all your allocations are the same size, or you're double-indirecting everything and running a compactor periodically). Among other things, every long-running X program is a perfect example of how to fragment your memory rather horribly. (side point: sure, if you have an entire memory page which is unused, your kernel will probably leave it in swap space, but when you've got fragmented memory, there's a good chance that there's a little 8 or 16 or maybe 64 byte block in the middle of your page that is still being used regularly) Dynamically allocating a large number of objects with very different sizes is _very_ bad in terms of memory fragmentation. Many people solve that problem by dynamically allocating all their strings in fixed sizes or size increments. But in such a case, all the memory savings you might have won by using dynamic allocation over static buffers is lost. When you consider that many (most?) malloc() implementations maintain pools of power-of-two sized blocks and simply manage those instead of trying to deal with blocks of any size, we're back in precisely that position of wasting memory. Now that the memory-saving argument is weakened, the static buffers look even more attractive to a programmer, in spite of their problems for security and program reliability. But, as I'm sure we've all shuddered to hear time and time again, "But this program isn't system critical, so we don't need to go to all that effort to make it robust." And after all: who would've thought that sort was system critical? -- Jon Paul Nollmann ne' Darren Senn sinster () darkwater com Unsolicited commercial email will be archived at $1/byte/day. Wasurenaide -- doko e itte mo soko ni iru yo.
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)
- Security problem in Slackware. Suman_Saraf (Mar 11)
- Possible Bug in CDE on HP-UX gareth greenaway (Mar 09)