Hi all,

Got rid of all the Integer.toString allocations by having my own
intToString method and using char[] as suggested.
The only thing showing now on the DDMS allocs are the
Drawable.setBounds calls (lots of them).
I've used both the rect version and the four-ints version of setBounds
but they both do the same thing.
I'll post some code in case someone can tell me what I'm doing wrong:

private AnimationDrawable m_animationDrawable;
m_animationDrawable = (AnimationDrawable)
m_inGameView.getResources().getDrawable(p_animDrawableID);

then my doDraw method looks like:
final void doDraw(final Canvas p_canvas, final Rect p_bbox, final
boolean p_applyColorFilter)

and it does the following:
m_animationDrawable.getFrame(m_currentFrame).setBounds(p_bbox.left,
p_bbox.top, p_bbox.right, p_bbox.bottom);
// some color filter stuff that's irrelevant to the leak go here
m_animationDrawable.getFrame(m_currentFrame).draw(p_canvas);

// m_currentFrame gets updated in doUpdate
// p_bbox is a rect that represents the drawable's bounding
box...different frames can have different bbox sizes (e.g. during an
explosion)

The call to setBounds above shows as an alloc in DDMS :(
I've called it passing p_bbox directly as well (i.e. the rect version
of setBounds) and it makes no difference.
How can I prevent the allocation there?

Thank you in advance,
kk.

On Nov 15, 8:37 pm, kk <[email protected]> wrote:
> Top stuff Kostya/Dianne. Thank you for the feedback.
> I think before I look into anything else, I should do this first to
> get
> rid of the thousands of micro-allocations that take place there.
>
> UI elements are drawn about 20 times per second and although I cache
> values that don't change, a lot of the values do change quite
> frequently.
>
> I'll report back if I'm still having issues after I do this.
>
> Thanx again,
> kk.
>
> On Nov 15, 7:31 pm, Kostya Vasilyev <[email protected]> wrote:
>
>
>
>
>
>
>
> > What I was suggesting was, rather than using Integer.toString(), or any
> > other String / StringBulider methods, format the value yourself.
>
> > In class declaration:
>
> > char[] mMyHealthStr = new char[8];
> > int mMyHealthLen = 0;
>
> > When drawing:
>
> > // convert integer to string in mMyHealthStr, set mMyHealthLen
>
> > canvas.draw(mMyHealthStr, 0, mMyHealthLen, ..... blah blah .....);
>
> > -- Kostya
>
> > 15.11.2010 21:48, Dianne Hackborn ?????:
>
> > > On Mon, Nov 15, 2010 at 8:37 AM, kk <[email protected]
> > > <mailto:[email protected]>> wrote:
>
> > >     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?
>
> > > You haven't gained anything here, because Integer.toString() has
> > > already had to make a string for that integer before you even get in
> > > to the StringBuilder.
>
> > > --
> > > Dianne Hackborn
> > > Android framework engineer
> > > [email protected] <mailto:[email protected]>
>
> > > Note: please don't send private questions to me, as I don't have time
> > > to provide private support, and so won't reply to such e-mails.  All
> > > such questions should be posted on public forums, where I and others
> > > can see and answer them.
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to