[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Avoiding consing when translating numbers to strings
Date: Thu, 2 Mar 89 10:06 CST
From: ai.gooch@MCC.COM (William D. Gooch)
FYI - you might want to try the following approach:
(make-array 10 :element-type 'string-char :fill-pointer 0))
(defun examine-number (num)
;; 1Protect the global parameter - format can set its first argument
0 (let ((outstr *temp-string*))
(setf (fill-pointer outstr) 0)
(format outstr "~F" num)
;; 1then deal with the string (in outstr)
This won't get you away from the bignum consing Barry mentioned, but it avoids
the need to stack-allocate a new string each time, minimizing the overhead of
building the strings. Probably will speed things up a bit. You have to be
careful because of format's modifying the global's contents in place. I like
to use this approach for short-lived things such as mouse documentation strings.
The problem with this approach is that it is not reentrant.
Remember, the Symbolics system DOES have multiple processes,
and c-m-Suspend, etc. A better way to accomplish the same
thing is to make a temp-string resource.