[gnu.emacs] Reducing Emacs memory usage

drw@BOURBAKI.MIT.EDU (02/20/89)

I was thinking that it is possible to write a compactifiying garbage
collecting algorithm for Emacs.  It wouldn't have to be fast, since it
need only be executed manually.  Here's how it would work:

0. Do garbage-collect.

1. Scan through all of Emacs's data structures and locate memory under
Emacs's control.  (This is more like the 'sweep' phase of
garbage-collect than the 'mark' phase.)  Build a table of all object
addresses found.  (Keep the table as a hash table or balanced tree for
fast access.  Allocate the table "manually", using setbrk, not malloc.)

2. Sort the table into order.

3. Scan through malloc's data structures to figure out where there is
empty space, and determine where each object will be relocated to
(slide all Emacs objects toward low memory as far as possible, but
preserve their order).  Remember there are malloc'ed things that are
not Emacs objects.

4. Going through the table in order, relocate each object.  Rebuild
malloc's data structures to reflect the new organization of allocated
and freed areas.

5. Use the table to correct all pointers to objects.  (Like the 'mark'
phase of garbage collection.)

6. Remove all free memory at the high end of virtual memory from
malloc's data structures, and use setbrk to release it back to the OS,
as well as the table.

What you need to do this successfully is understand Emacs's memory
allocation strategy (which is in the source code), and understand how
malloc really works (which can be gotten from the source, or by
disassembling malloc and free).  One version should work fine for most
BSD Un*x's.  A perfect project for some hacker to affirm his manhood.

Dale

gz@spt.entity.com (Gail Zacharias) (02/20/89)

In article <8902192040.AA05567@laurent.mit.edu> drw@BOURBAKI.MIT.EDU writes:
>A perfect project for some hacker to affirm his manhood.
>Dale

Oh my, and you almost had me convinced to give it a try... But I guess this
one's strictly for the boys.

--									  --
gz@entity.com						...!mit-eddie!spt!gz

HUXTABLE@KUHUB.CC.UKANS.EDU (Kathryn Huxtable) (02/21/89)

In message <8902192040.AA05567@laurent.mit.edu>
Dale Bourbaki proposes a project to compact Emacs's memory and closes:

>A perfect project for some hacker to affirm his manhood.

Can't we say this some other way?  Say "A perfect project for
demonstrating prowess at hacking."  Or something.  Language is
important.

-Kathryn