[Openmcl-devel] %temp-cons

Robert Munyer 2420506348 at munyer.com
Sun May 26 17:46:39 PDT 2024


> On May 21, 2024, at 1:30 PM, R. Matthew Emerson <rme at clozure.com> wrote:
>
>> Does anyone know/remember what %temp-cons is?  Some artifact
>> from days gone past?
>>
>> It looks like it's currently just an alias for regular cons.
>>
>> There's a %temp-list, too.

Garbage prevention.

I believe that when a CCL developer uses any of these:

  %arglist
  %temp-cons
  %temp-list
  %temp-push
  make-tsp-cons
  ppc2-%temp-cons
  ppc2-%temp-list
  temp-cons
  x862-%temp-cons
  x862-%temp-list

he or she is asserting that the cells being constructed will become
unreachable garbage, before or during destruction of the current stack
frame, so they can be constructed in the "temp stack" [1] instead of
in the heap, so their space can be reclaimed by a mechanism that's
vastly more efficient than garbage collection.

There's another way to construct cells in the temp stack, but it's
cumbersome.  Here are two functions, equivalent except that the latter
constructs a cell in the temp stack instead of in the heap:

  (defun foo ()
    (length (cons t nil)))

  (defun bar ()
    (let ((baz (cons t nil)))
      (declare (dynamic-extent baz))
      (length baz)))

If you evaluate "(time (foo))" and "(time (bar))", you should get
a "bytes of memory allocated" line from FOO but not from BAR.

Simply inserting "%temp-" would be much less cumbersome.

-- Robert Munyer

[1] See https://ccl.clozure.com/docs/ccl.html#stack-conventions


More information about the Openmcl-devel mailing list