#Zero Allocation TMP_Text

1 messages · Page 1 of 1 (latest)

merry quarry
#

I use ZString to non GC alloc for string, however the TMP_SetText is still exist on Resize Array or something.

gentle axle
gentle axle
merry quarry
#

using SetCharArray

#

What's the point of using char array if its going to be changed to string in the internal

#
 private string InternalTextBackingArrayToString()
 {
     char[] array = new char[m_TextBackingArray.Count];
     for (int i = 0; i < m_TextBackingArray.Capacity; i++)
     {
         char c = (char)m_TextBackingArray[i];
         if (c == '\0')
         {
             break;
         }

         array[i] = c;
     }

     m_IsTextBackingStringDirty = false;
     return new string(array);
 }
merry quarry
gentle axle
#

Sounds familiar, but I don't remember any details.

merry quarry
weak knot
#

Hi! I can confirm that TMP_Text does indeed allocate and we don't have a way to avoid that at this time. We might implement a refactor that will address this issue, but cannot say when that will be.

merry quarry
#

and is 100% only in editor?

merry quarry
#
 // Make sure array size is appropriate
            if (length >= m_TextBackingArray.Capacity)
                m_TextBackingArray.Resize((length));

If only there's a way to preAllocate