[Top][All Lists]

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

Re: Object identity

From: Barry Margolin
Subject: Re: Object identity
Date: Tue, 21 Oct 2003 15:44:30 GMT

In article <>,
Lars Brinkhoff  <> wrote:
>(Would emacs-devel be a more appropriate list to post this?)
>Is there a function, say object-identity, in Emacs Lisp that maps an
>object to a unique value (other than the object itself)?  For example,
>the value could be an integer, or a list of integers, or a string,
>that represents the memory address of the object.
>To clarify, this function would have the property that
>    (equal (object-identity obj1) (object-identity obj2))
>if and only if
>    (eq obj1 obj2)

I'm not sure it's possible to write such a function without significant

Suppose it just returns the object's address as an integer.  This satisfies
the requirement

  (eq obj1 obj2) -> (equal id1 id2)

But then the object gets GC'ed, and a new object is allocated at the same
address.  When you ask for the new object's identity, you'll get the same
value as was previously returned for the old object, even though the
objects are not eq.

So let's try augmenting it with additional information, like a timestamp.
This obviously can't be the time that object-identity was called, because
then it will be different every time.  It needs to be something associated
with the object itself, like the time it was created or the time that
object-identity was first invoked on it.  This implies that every object
needs to have a slot to store its creation time.  As a result, the size of
every object will have to grow by at least 4 bytes.  Assuming cons cells
are 8 bytes, this means increasing the space they use by 50%.  Since most
objects in memory will never have object-identity called on them, this
space is mostly wasted.

Barry Margolin,
Level(3), Woburn, MA
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]