[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to ask "how big is it?"



    Date: Mon, 7 Sep 87 14:50 EDT
    From: David L. Andre <DLA@DIAMOND.S4CC.Symbolics.COM>

	Date: Fri, 4 Sep 87 15:05 EDT
	From: Mark H. Shirley <MHS@HT.AI.MIT.EDU>

	I've used the document examiner to search for this, without any luck.  Does
	anyone have a utility that grovels over an object in memory and reports on how
	much storage it occupies?  I found SYS:%STRUCTURE-TOTAL-SIZE, but this doesn't
	chase pointers (e.g. to include all objects accessible in a linked
	datastructure).

    You have to define what you're looking for.  If you think about it a
    little, you'll see that it's not an easy problem.  (For instance, how
    much room does a symbol take up?  5 words?  Or do you chase the pointer
    to the package and find out that it points to every other symbol in the
    world?  Every application has to define what an "important" pointer is.)

    I usually end up writing my own tool for each application.  Just write a
    quick function which knows how to map over your database, use a hash
    table to detect circularities, and then sum up the %STRUCTURE-TOTAL-SIZE
    of everything in the hash table.

My assistant's technique has a problem with cdr-coded lists getting
counted multiple times.  I would use 

(SI:%FIND-STRUCTURE-HEADER (SI:FOLLOW-STRUCTURE-FORWARDING thing))

on the objects you care about, using the returned header as the key into
the hash table, and then sum %STRUCTURE-TOTAL-SIZE of the hash table
elements. 

    Don't get fooled by the following phenomenon with lists:

    (%STRUCTURE-TOTAL-SIZE (LOOP FOR I BELOW 1000 COLLECT I)) ==> 2

    The reason is left as an exercise.