all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Object identity
@ 2003-10-21  6:07 Lars Brinkhoff
  2003-10-26 17:30 ` jan
  0 siblings, 1 reply; 20+ messages in thread
From: Lars Brinkhoff @ 2003-10-21  6:07 UTC (permalink / raw)


(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    http://www.brinkhoff.se/

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2003-10-26 22:45 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.2049.1066716515.21628.help-gnu-emacs@gnu.org>
2003-10-21 15:09 ` Object identity Stefan Monnier
2003-10-21 16:55   ` Stefan Monnier
2003-10-21 19:00   ` Lars Brinkhoff
     [not found]   ` <mailman.2095.1066762882.21628.help-gnu-emacs@gnu.org>
2003-10-21 19:27     ` Barry Margolin
2003-10-21 19:49       ` Lars Brinkhoff
     [not found]       ` <mailman.2101.1066765792.21628.help-gnu-emacs@gnu.org>
2003-10-21 19:56         ` Barry Margolin
2003-10-22  7:35           ` Lars Brinkhoff
2003-10-21 15:44 ` Barry Margolin
2003-10-21 16:09   ` Stefan Monnier
2003-10-21 16:19     ` Barry Margolin
2003-10-21 16:50       ` Stefan Monnier
2003-10-21 17:19         ` Barry Margolin
2003-10-21 17:42   ` Lars Brinkhoff
     [not found]   ` <mailman.2089.1066758667.21628.help-gnu-emacs@gnu.org>
2003-10-21 19:59     ` Stefan Monnier
2003-10-21 20:13       ` Lars Brinkhoff
     [not found]       ` <mailman.2104.1066767237.21628.help-gnu-emacs@gnu.org>
2003-10-21 21:22         ` Stefan Monnier
2003-10-21 21:39           ` Barry Margolin
2003-10-21  6:07 Lars Brinkhoff
2003-10-26 17:30 ` jan
2003-10-26 22:45   ` jan

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.