#Zero Allocation TMP_Text
1 messages · Page 1 of 1 (latest)
I imagine TMP has to manage an internal buffer to hold the data you pass to it. Does it allocate on every call?
yes
On the same instance with data that is either the same size or smaller?
will check tomorrow
I ran it per frame, and it was the same string
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);
}
Seems to be one of those editor only things https://github.com/needle-mirror/com.unity.textmeshpro/blob/75fef8b868509a5496d5d67bd912153a3aa149cc/Scripts/Runtime/TMP_Text.cs#L2783
wasnt there a feature where we can highlight the profiler to be [Editor Only] like that
Sounds familiar, but I don't remember any details.
and AFAIK the feature is internal to the engine. its usually popup when we use GetComponent<T> but returns null
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.
do you have any insights, maybe I can do it manually?
and is 100% only in editor?
// Make sure array size is appropriate
if (length >= m_TextBackingArray.Capacity)
m_TextBackingArray.Resize((length));
If only there's a way to preAllocate