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

Re: Best way to convert integer to string?

In article <...> psto@xs4all.nl (Peter Stone) writes:

 > I'm updating counters as a periodic task on a window while playing a
 > MIDI sequence. From time to time the counters will freeze. I'm using
 > princ-to-string to convert the counter values to strings before
 > printing with #_DrawString. I'm suspecting that freezing is caused by
 > ephemeral garbage collection, and endeed when I test princ-to-string
 > it makes lots of garbage:
 > Is there a better way to print integers?

Two things to try looking at are:

  with-output-to-string where you specify a string buffer to use.
  format to a string output destination.

In both cases you will need to allocate a string with a fill pointer.
The output will then fill the string as necessary.  It may take a little
experimentation to figure out if you need to reset the fill pointer of
if the output function does that for you.  That way you will only have
to allocate the string once and keep it around for reuse.  That will
eliminate the garbage associated with generating new strings each time.

Thomas A. Russ,  USC/Information Sciences Institute          tar@isi.edu