Subject: Re: Memory Allocation in Lisp?
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 08 Jul 2004 20:39:48 -0500
Newsgroups: comp.lang.lisp
Message-ID: <gNqdnZhugej5anDd4p2dnA@speakeasy.net>
Paul Wallich  <pw@panix.com> wrote:
+---------------
| neo88 wrote:
| > And just to clarify, numbers and characters do NOT work like pointers?
|
| Numbers and characters don't work like pointers in the sense that
| they're not (generally) unique objects, so you can't do the shorthand
| of asking whether two of them are equal to another by seeing if they
| point to the same place (the EQ test).
+---------------

But on the other hand, you can never be sure that they *aren't* pointers,
either. Both bignums (anything bigger than MOST-POSITIVE-FIXNUM) and
"fat" characters (if your implementation supports them) might very well
be heap-allocated.[1]

When explaining this to newcomers, I find it easier to simply say that
in Lisp *everything* is a pointer[2], except that the implementation
is allowed to optimize the representation of some objects by encoding
them as "funny" or "immediate" pointers.


-Rob

[1] The original SIOD implementation of R3RS Scheme (later used in
    The GIMP as an extension language) represented *all* numbers
    as heap-allocated C "doubles", but lessened the strain on the
    allocator by consing a small range of whole numbers (typically
    -100.0 through 1000.0) at startup time. Numeric functions did
    a quick range check on their results and returned one of the
    preallocated numbers if possible.

[2] Though this really bothers some purists [search Google Groups for
    "everything is a pointer"] who would prefer to say "everything is
    an object" and then mumble something about usually never needing
    to know whether the representation of an object is a pointer to
    a hunk of heap or an immediate pointer-like cookie (or even an
    unboxed native machine type).

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607