[Top][All Lists]

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

Object identity

From: Lars Brinkhoff
Subject: Object identity
Date: 21 Oct 2003 08:07:57 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

(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)

This is my current implementation.  However, my version of Emacs
doesn't implement weak hash tables, so it will make memory leak.
Any ideas about how to deal with that?

    (defvar object-identities (make-hash-table :test 'eq :weakness t))
    (defvar identity-counter 0)
    (defun object-identity (object)
      (or (gethash object object-identities)
          (setf (gethash object object-identities)
                (incf identity-counter))))

(Yes, I'm aware the counter will eventually wrap around...)

Lars Brinkhoff,         Services for Unix, Linux, GCC, HTTP
Brinkhoff Consulting

reply via email to

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