[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: view-cursor



At 19:11 12/15/92 -0500, Dale J. Skrien wrote:
>I've created a special subclass of view for which I want to continually
>display the mouse position when it is over the view.  I want the mouse
>position to be displayed in the view-window of the view but outside
>of the view.  So I wrote a method of view-cursor for my view as follows:
>
>(defmethod view-cursor ((self my-special-view-class) where)
>  (with-focused-view (view-window self)
>    (#_textmode #$patCopy)
>    (with-pstrs ((horizontal (format nil "~3d" (point-h where)))
>                 (vertical (format nil "~3d" (point-v where))))
>        (#_moveto 10 10)
>        (#_drawstring horizontal)
>        (#_moveto 10 40)
>        (#_drawstring vertical)))
>  *arrow-cursor*   ;return the arrow cursor
>  )
>
>My Question:  Is this the best way to do it (time-wise and
>memory-wise)?  In particular, does this do some cons-ing that
>will rapidly eat up memory while the mouse is over the view?

You're consing two 3-character strings each time your view-cursor
method runs. (format nil ...) conses a string. You'd do better to
FORMAT directly to the window:

(defmethod view-cursor ((self my-special-view-class) where)
  (let ((window (view-window self)))
    (with-focused-view window
      (#_textmode #$patCopy)
      (#_moveto 10 10)
      (format window "~3d" (point-h where))
      (#_moveto 10 40)
      (format window "~3d" (point-v where))))
  *arrow-cursor*   ;return the arrow cursor
  )

Unfortunately, this still conses because MCL's FORMAT ~D code conses if
you specify a MINCOL argument. Two choices: do the numeric conversion
yourself or ask for my patch that eliminates the consing from MCL's
FORMAT ~D code. The patch is called "less-format-consing-patch.lisp".
(This has bothered me for a while. Thanx for giving me the impetus to
spend an hour fixing it)