Object Address in Memory Common Lisp

1k Views Asked by At

I am trying to figure out how software like SLIME or SLY gets the memory addresses of variables as it displays them in the Inspector. What Common Lisp function could I use to be able to do this programatically?

Example:

enter image description here

It is the #x100cab066d1 that is of interest here.

1

There are 1 best solutions below

0
On

You don't want to: garbage collection may (and often does!) move objects, so the address of an object may be different between observations. Another problem is posed by immediate objects (e.g., 1 or #\A) - what would their addresses be?!

That said, ANSI CL offers the :identity argument to print-unreadable-object which most lisps interpret to mean the current address in memory.

Alas, the output format is implementation-dependent (e.g., SBCL wraps the address in {}), so it is better to find the implementation-specific function which returns the address.

Using apropos, we easily find

  • system::address-of in CLISP;
  • sb-kernel:get-lisp-obj-address in SBCL.

PS. Check out sxhash - could that be what you are looking for?