[Openmcl-devel] calcultaing memory use.
mb at bese.it
Mon Nov 15 13:02:32 EST 2004
Gary Byers <gb at clozure.com> writes:
> Determining how much memory a given lisp object takes up is fairly
> simple: conses are a pair of 32-bit words, everything else has a
> 32-bit header on the front of it and everything is aligned on a
> doubleword boundary. (See the code attached to the message cited
> above for details.)
here's my main question:
if "conses are pairs of 32 bits words, and everything else has a 32
bit header, and everything is double word aligned" then the size of
an array is it's length + 32 bits + the size of all non immediate
objects it contains. a hash table is the size of its various
properties (size, test, rehash count, etc.) + 32 bits + (* 2
hash-table-size) + the size of all non immediate keys and values.
if this analysis is right, is there a way to generalize this and work
with the uvector instead of having to write multiple object traversal
functions? (in particular i'd like to know how much "stuff" closures
are forcing me to keep around and this is going to require some
all of these questions, and the uvector walking idea, stem from the
fact that your classify-object function, slighty modified to size of
its argument, does this:
CCL> (classify-object "a")
CCL> (classify-object "abcde")
CCL> (classify-object (make-hash-table :size 0))
CCL> (classify-object (make-hash-table :size 1000))
which is close to what i'm trying, but not quite there.
(defun classify-object (o)
(if (consp o)
(values 8 'cons)
(let* ((typecode (typecode o))
(elements (uvsize o))
(vector-type (ash typecode -3)))
(declare (fixnum typecode elements vector-type))
(if (= (logand typecode ppc32::fulltagmask) ppc32::fulltag-immheader)
(values (logandc2 (+ 11 (subtag-bytes typecode elements)) 7)
(svref *immheader-types* vector-type))
(values (logandc2 (+ 7 (the fixnum (* 4 (1+ elements)))) 7)
(svref *nodeheader-types* vector-type))))))
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
More information about the Openmcl-devel