Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - smartie

Pages: [1]
1
NGUI 3 Support / Re: Avoiding the garbage collector with UILabel.text
« on: September 01, 2014, 04:10:41 AM »
I hope you're at least checking whether DistanceCurrentScore has changed before doing any of that StringBuilder stuff...

yep the design of the game means that score changes every frame.

2
NGUI 3 Support / Re: Avoiding the garbage collector with UILabel.text
« on: August 29, 2014, 04:16:26 AM »
yes it's true that ToString() causes allocations but we only need to do that because UILabel.text is an immutable string so we need an allocation to change it. If UILabel.text had an overload that took a char array then we could write directly into that array without any allocation.


3
NGUI 3 Support / Avoiding the garbage collector with UILabel.text
« on: August 28, 2014, 11:42:33 AM »
Is there any way of setting the text in a UILabel without allocating memory?

We have some code that is setting the current score every frame like this like this:

  1. stringBuilder.Remove(0, _stringBuilder.Length);
  2. stringBuilder.Append(DistanceCurrentScore);
  3. string textScore = stringBuilder.ToString();
  4. scoreLabelHUD.text = textScore;
  5.  

And this causes memory allocations every frame because UILabel.text is a string, which is immutable, so has to be recreated every time we want it to change.

Is there an alternative way of setting a text value for a UILabel which doesn't allocate memory?

Pages: [1]