Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!lll-winken!ubvax!ardent!mac From: mac@rhea.ardent.com (Mike McNamara) Newsgroups: gnu.emacs Subject: Re: Why Gnu Emacs doesn't release memory Message-ID: Date: 30 Oct 89 19:28:02 GMT References: <8910261557.AA02573@sn1987a.compass.com> Sender: news@ardent.UUCP Reply-To: mac@ardent.com (Michael McNamara) Distribution: gnu Organization: Ardent Computer Corporation, Sunnyvale, CA Lines: 42 In-reply-to: compass!worley@EDDIE.MIT.EDU's message of 26 Oct 89 15:57:06 GMT In article <8910261557.AA02573@sn1987a.compass.com> compass!worley@EDDIE.MIT.EDU (Dale Worley) writes: > The traditional solution to such problems is called 'compactification' > -- moving all in-use data areas into a compact mass at the low end of > the data area, and then deallocating the huge free area left at the > high end. To do this successfully requires that all pointers to any > data area be altered to point to the new addresses, which (despite > some earlier speculations of mine) requires much careful design and is > very error-prone. Could you just add one level of indirection to the memory allocation scheme? ie. define a new malloc to be char ** gc_malloc(unsigned int); instead of char * malloc(unsigned int); You also need a gc_lock(char**); and gc_unlock(char**), which allow modules to temporarily gain protection for a dereferenced pointer. [Perhaps this is what you mean by careful design and error prone.] You slowly migrate the potentially large memory allocators to this scheme. I have programmed a number of PC's which used the above scheme to manage memory. Then when compactifing, you simply deal with those of your internal list of char*s which are not currently gc_lock'ed. At the expense of an additional dereference for every pointer usage (non trivial, yes, but 32MHz is pretty fast..), this allows simple, save memory compactification. > > Dale Worley Compass, Inc. worley@compass.com > --