From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: malloc & free Date: Wed, 01 Apr 1998 18:45:11 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 32 Message-ID: <3522D187.71A@cs.com> References: <352140E9 DOT D07CEE53 AT krona DOT obninsk DOT ru> <3521822F DOT 6B13 AT cs DOT com> <352299EA DOT 5F1FF492 AT johnbryce DOT co DOT il> NNTP-Posting-Host: ppp217.cs.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 Precedence: bulk Noam Rotem wrote: > > John M. Aldrich wrote: > > > The answer is quite simple: DJGPP's malloc()/free() does not return > > freed memory blocks to the system; it keeps track of them for possible > > reuse later. At program termination, all allocated memory is returned > > to the DPMI host. > > Is it faster to reuse freed memory than asking the dpmi server for it again? The best answer is that it depends on the system and the DPMI host. However, since those are variable quantities, while the amount of time it takes malloc() to reuse blocks is a) fixed, and b) very fast, it's almost a given that reusing blocks will be faster. Many applications do this kind of "caching" internally as well, assuming that stock malloc() and free() may be slower than ideal. The current DJGPP malloc() is optimized for speed, so it uses a number of techniques that might seem wasteful, such as rounding block sizes and reusing freed blocks. A few months ago, DJ ran some open tests on various alternative malloc() routines, and eventually settled on a more efficient algorithm that he plans to put into DJGPP v2.02. Until then, you'll have to settle for the original. -- --------------------------------------------------------------------- | John M. Aldrich | "Always listen to experts. They'll | | aka Fighteer I | tell you what can't be done, and why.| | mailto:fighteer AT cs DOT com | Then do it." | | http://www.cs.com/fighteer/| - Lazarus Long | ---------------------------------------------------------------------