[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Avoiding consing when translating numbers to strings
- To: STERRITT%SDEVAX.decnet@GE-CRD.ARPA
- Subject: Avoiding consing when translating numbers to strings
- From: "William D. Gooch" <ai.gooch@MCC.COM>
- Date: Thu, 2 Mar 89 11:06:00 EST
- Cc: slug@WARBUCKS.AI.SRI.COM
- Character-type-mappings: (1 0 (NIL 0) (:SWISS :ROMAN :SMALLER) "HL10")
- Fonts: CPTFONT, HL10
- In-reply-to: The message of 1 Mar 89 15:44 CST from STERRITT%SDEVAX.decnet@ge-crd.arpa
FYI - you might want to try the following approach:
(defparameter *temp-string*
(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)
0 ))
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.