Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Copying data between jobs

Discussion in 'Entity Component System' started by TylerMorton, Mar 22, 2018.

  1. TylerMorton

    TylerMorton

    Joined:
    May 24, 2015
    Posts:
    2
    Hi guys,

    I've just gotten started with using the new C# Jobs system. So far so good. I've run into a couple of things that I am confused about.

    The documentation for Allocator is very vague. Can someone explain to me what the difference is between different Allocation modes?

    Thanks in advance :)
     
    Last edited: Mar 23, 2018
  2. GabrieleUnity

    GabrieleUnity

    Unity Technologies

    Joined:
    Sep 4, 2012
    Posts:
    116
    @TylerMorton

    I will update the docs with more details, but to give a bit more in-depth information:

    - Invalid: it is an invalid allocation strategy. It is used internally for validation. It shouldn't normally appear in any runtime code other than default-initialized memory or broken code;
    - None: it means that the memory the container points to has been allocated somewhere else, and thus the container doesn't own it. It is mostly used internally when we create temporary NativeArrays out of buffers allocated by other means. I'm not sure if we publicly expose any API yet where it makes sense to use Allocator.None;
    - Temp: It is a temporary allocation, performed using a very efficient memory allocator. Memory allocated this way is supposed to be used within the current frame and Disposed before the end of it. Referencing memory allocated this way in subsequent frames is invalid and will result in a leak.
    - TempJob: It is a temporary allocation, performed using a very efficient memory allocator, specifically tailored for short running Jobs. Memory allocated with TemJob is valid for 3/4 frames after it allocations, so it has to be Disposed earlier than that. Referencing memory allocated this way in subsequent frames is invalid and will result in a leak.
    - Persistent: it is a normal persistent native allocation, similar to use malloc on the C++ side (it goes through our optimized native memory allocators, but it is just to give you an idea). The memory allocated this way will have to be disposed manually or will stay allocated forever. This allocation strategy is used for long living allocations.
     
    Cynicat likes this.
  3. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    Great info! Can somebody copy paste this explanation into the docs, that was way more useful than "Persistent allocation" X3
     
  4. GabrieleUnity

    GabrieleUnity

    Unity Technologies

    Joined:
    Sep 4, 2012
    Posts:
    116
    We already extended the docs, written in better Eglish too :)

    The update will be available soon.
     
    Cynicat and recursive like this.