Search Unity

"allocate managed memory"

Discussion in 'Entity Component System' started by laurentlavigne, Oct 18, 2020.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,362
    I read in the doc "do not allocate managed memory" inside a Job.

    So far I've only let unity handle memory so i don't know what's what.

    Can you guys give me a few example of allocating managed memory apart from obvious things like
    new List<>
    or string concats.

    For example does
    var f=Mathf.Sin(t)
    or any float temp variables allocate managed memory?
     
  2. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    298
    Managed types are pretty much any reference type, which classes are. Reference types have their memory managed by the CLR. Structs like float or a struct you create without reference types contained are unmanaged. If the method does not create or work with a managed type, then that's fine.

    C# docs can probably explain things better than I can:

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/unmanaged-types

    https://docs.microsoft.com/en-us/dotnet/standard/managed-code
     
    Last edited: Oct 19, 2020
    laurentlavigne and apkdev like this.
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,362
    Thanks! All clear