Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What is the "fast memory allocator" for "local strings"?

Discussion in '2020.2 Beta' started by sbeeman_hbs, Sep 21, 2020.

  1. sbeeman_hbs

    sbeeman_hbs

    Joined:
    Dec 5, 2019
    Posts:
    1
    The "new performance improvements in 2020.2" blog post says this:
    The team replaced lots of slow string memory allocations with temp memory labels, for strings that only exist within a single frame. In practice, most strings in Unity exist only as local variables within a single function call, so they can use a fast memory allocator. Most string utility functions now use temp memory.​

    Working more efficiently with strings is highly relevant to my interests. Can you elaborate on what you're doing? Is this on the native C side, or is this happening in CLR code? If the latter, is this just using stackalloc in unsafe code, or some other mechanism?
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,270
    The fast allocator is mainly only usable on the native side for strings, but we do expose some of the same features in script for some non-string types.

    For example, the fast memory allocator is very similar to what is used if you create a NativeArray with the Allocator.Temp parameter.
     
    Peter77 and LeonhardP like this.