From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Bug in malloc/free ? Date: Thu, 06 Mar 1997 21:28:57 -0800 Organization: Alcyone Systems Lines: 40 Message-ID: <331FA799.635C4091@alcyone.com> References: <5fm6r7$6av$1 AT gjallar DOT daimi DOT aau DOT dk> <331EF4EF DOT 3788CF9D AT alcyone DOT com> <19970306 DOT 200419 DOT 4511 DOT 3 DOT fwec AT juno DOT com> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Mark T Logan wrote: > The only catch is that your manager can't give out addresses when you > call its > allocation function. This is because if it goes and collects the > garbage, all the > addresses change. So, you have to give out handles. A handle is the > address > of a location in memory where you have stored the address of an allocated > block. This means that your manager has the one and only copy of the > chunks > address, and can change the address when it moves a chunk. In this case you then need lock and unlock functions, to lock down a handle so that it won't move when you do memory-intensive operations that might move blocks around in memory. As a word of warning: This kind of memory management system is only necessary when you have very limited memory, or if you know that memory will get completely fragmented with all sorts of varying-size blocks. What you end up with is something like the Macintosh Memory Manager. Overall it wasn't a bad idea, but in 1997 it has become almost completely unnecessary, and has given programmers untold numbers of headaches, uncurable with aspirin. (And there's the fact that the Macintosh operating system doesn't handle application memory with this kind of situation, so while memory won't get fragmented within an application heap zone, it _will_ get fragmented between them. Ugh.) The short answer is that a suballocator is usually more than sufficient, especially when you know that the blocks will all be of a certain size, which is what the original poster seemed to be needing. -- Erik Max Francis, &tSftDotIotE / email: max AT alcyone DOT com Alcyone Systems / web: http://www.alcyone.com/max/ San Jose, California, United States / icbm: 37 20 07 N 121 53 38 W \ "I am become death, / destroyer of worlds." / J. Robert Oppenheimer (quoting legend)