all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Barry Margolin <barry.margolin@level3.com>
Subject: Re: Object identity
Date: Tue, 21 Oct 2003 15:44:30 GMT	[thread overview]
Message-ID: <yvclb.124$lK3.43@news.level3.com> (raw)
In-Reply-To: mailman.2049.1066716515.21628.help-gnu-emacs@gnu.org

In article <mailman.2049.1066716515.21628.help-gnu-emacs@gnu.org>,
Lars Brinkhoff  <lars@nocrew.org> 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
overhead.

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, barry.margolin@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

  parent reply	other threads:[~2003-10-21 15:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='yvclb.124$lK3.43@news.level3.com' \
    --to=barry.margolin@level3.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.