Latest Tweets

 

Creating numbers without garbage

I’m pretty sure that I’ve seen a few questions asked about stuttering framerates within Android games that were be traced to the garbage collection of String objects generated by Integer.toString().

Avoiding GC cycles is important in animations and games. The Android Canvas class helpfully gives you a drawText method that takes a char[] rather than a String for just this reason.

All you need is some code that will write your integer into a character array. Here’s a small class just for that:

  1. tomgibara posted this
blog comments powered by Disqus