George,

Is it meant to alloc every time you call it then?
That's going to cause GC to collect at random times during my game :(

cheers,
kk

On Nov 15, 4:40 pm, george barber <finchbar...@gmail.com> wrote:
> no your not using it wrong
>
>
>
> On Mon, Nov 15, 2010 at 4:37 PM, kk <kkostia...@gmail.com> wrote:
> > Just to make sure, can someone please tell me if I'm misusing
> > StringBuilder here.
> > This is what I do:
>
> > private StringBuilder m_healthString = new StringBuilder(8);
>
> > I update by doing:
> > m_healthString.replace(0, 8, Integer.toString(myHealth));
> > Is this expensive/wrong? Is there a better way to update a
> > StringBuilder with a new String?
>
> > I render by doing:
>
> > myCanvas.drawText(m_healthString, ...); // this is using the char[]
> > version, which is good
>
> > Obviously I will look into a custom version of Integer.toString, which
> > will
> > eliminate quite a lot of the allocations in there.
>
> > cheers,
> > kk.
>
> > On Nov 15, 1:17 pm, Kostya Vasilyev <kmans...@gmail.com> wrote:
> > > SetBounds has a version that takes four integers - no "new Rect" is
> > > necessary.
>
> > > As for Integer.toString - it's easy enough to write your own version
> > > that outputs the result into a supplied "char[]" buffer, that's only
> > > allocated once. Canvas.drawText() has a version that takes char[].
>
> > > But I suspect it's something else. Why are you calling System.gc, if
> > > you've gone to great lengths to minimize memory allocations? Perhaps
> > > you're calling it too much?
>
> > > -- Kostya
>
> > > 15.11.2010 16:09, kk пишет:
>
> > > > DanH,
>
> > > > I've had a look at the allocations using DDMS. The only things that
> > > > are being allocated during the game (that I have control over) are
> > > > Integer.toString and Drawable.setBounds calls.
>
> > > > Also, I calling System.gc() periodically and it logs the time taken
> > > > to do the collection...It doesn't seem to be increasing with time.
>
> > > > I'll try profiling as suggested by Dianne but this is very weird and
> > > > is holding up my release :(
>
> > > > cheers,
> > > > kk.
>
> > > > On Nov 15, 1:59 am, DanH<danhi...@ieee.org>  wrote:
> > > >> My guess is that you have a slow memory leak, and GC is taking more
> > > >> and more time (and happening more frequently) as the garbage builds
> > > >> up.  You need some traces and profiling to figure out what's going on.
>
> > > >> On Nov 14, 12:54 pm, kk<kkostia...@gmail.com>  wrote:
>
> > > >>> Hi all,
> > > >>> I've written a game and I've noticed that after playing for about
> > > >>> 20-30 minutes the performance starts degrading.
> > > >>> By performance degradation I mean my average frames-per-second seem
> > to
> > > >>> slowly drop.
> > > >>> I've no idea what could be causing this so any help would be greatly
> > > >>> appreciated.
> > > >>> I'm doing all my allocs at the beginning and the only things that
> > > >>> alloc in game according to DDMS are
> > > >>> Integer.toString operations (for integer values I need to draw with
> > > >>> drawtext) and setBounds on some drawables.
> > > >>> (I've no idea how to stop these from happening, so again, if you know
> > > >>> a way around this please do tell).
> > > >>> I'm calling System.gc() periodically, when I know not much is going
> > on
> > > >>> in-game (e.g. between waves of enemies).
> > > >>> I'm doing this in order to avoid GC from happening during critical
> > > >>> gameplay periods.
> > > >>> If you know the answer to any of the following, please do tell (even
> > a
> > > >>> guess would do :)):
> > > >>> + Why is performance degrading with time? What could be causing this?
> > > >>> + Is there a way to avoid allocs due to Integer.toString and
> > > >>> Drawable.setBounds calls?
> > > >>> Thank you in advance,
> > > >>> kk.
>
> > > --
> > > Kostya Vasilyev -- WiFi Manager + pretty widget --
> >http://kmansoft.wordpress.com
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com<android-developers%2Bunsubs 
> > cr...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to