Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Rewindable Allocator, what's the point ?

Discussion in 'DOTS Dev Blitz Day 2023 - Q&A' started by HBG-Mathieu, Aug 23, 2023.

  1. HBG-Mathieu

    HBG-Mathieu

    Joined:
    Feb 16, 2023
    Posts:
    59
    Hello,

    So I'm fine with classic Allocators (Temp, TempJob, Persistent) even if I don't know why it's 4 frames and not 1. But I'm completely lost since I saw there is now Rewindable allocators !
    And looks like there is no samples and most pages of the manual are dead links.

    So I'm trying to project myself using the EntityCommandBuffer, and I guess it's some kind of linked list where you can grow the memory over time because you're kind of preparing something to execute and you don't know the size of the memory at the starting point... like a dynamic buffer. Same idea as a simple malloc ?
    If it's that, I kinda see why it's useful for EntitCommandBuffer. But I absolutely have no idea when I could be using something like that in my game. So I think I'm not seing the whole picture, especially when I think about worldupdate and systemgroup allocator.
    Could you illustrate them with some uses case please?

    Thanks !
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    One use case is Netcode, that uses rewindable allocator for the fixed update groups and prediction groups too.
    Just to mention one.
     
    HBG-Mathieu likes this.
  3. barbara-wang

    barbara-wang

    Unity Technologies

    Joined:
    Jul 17, 2020
    Posts:
    5
    Greetings,

    We appreciate your questions and apologize for the inconvenience caused by the broken links. The broken links seem to be documents directing to the Collections package. You can find these documents at https://docs.unity.cn/Packages/com.unity.collections@2.1/manual/allocator-overview.html

    Rewindable allocator is a custom allocator which is a fast and thread-safe allocator, also useful to build other custom allocators. For instance, WorldUpdate allocator, EntityCommandBuffer Allocator and SystemGroup allocator are all constructed from Rewindable allocator. Rewindable allocator operates like a memory pool where memory blocks are pre-allocated in advance. When a user requests memory, it identifies available memory in a block and returns back, so it is fast. One of its advantages is that Rewindable allocator eliminates the need to manually free individual allocations, it rewinds and frees all allocations at one point. For details of Rewindable allocator and sample code as how to use it, please refer to https://docs.unity.cn/Packages/com.unity.collections@2.1/manual/allocator-rewindable.html

    Each entity command buffer system creates its own dedicated EntityCommandBuffer allocator. This allocator is responsible for memory allocations during the recording of the entity command buffer and deallocates the memory after the buffer is played back. It operates behind the scenes, requiring no explicit code changes from the user's end. For details, please refer to https://docs.unity3d.com/Packages/c.../manual/allocators-entity-command-buffer.html

    Every world creates a WorldUpdate allocator, which contains a double Rewindable allocators. It is useful for fast, thread-safe temporary allocations which do not need to be explicitly disposed. All allocations from WorldUpdate allocator are automatically disposed after two full world updates, so there isn't any memory leakage. It's like garbage collection, but significantly faster. Unlike Allocator.Temp, you can pass allocations from the WorldUpdate allocator into a job. Because the two Rewindable allocators of the WorldUpdate allocator are switched in each world update, it's advised not to cache the WorldUpdate allocator. For details and sample code, please refer to https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/allocators-world-update.html

    The primary objective behind the SystemGroup allocator is to manage allocations within a system that updates at a different rate - either fixed or variable - from the world update. It serves as an alternative to the WorldUpdate allocator for system groups updating in fixed or variable rates, where the default WorldUpdate allocator might not be suitable. Allocations by SystemGroup allocator last for two system group updates, eliminating the requirement for manual deallocations. As an optional feature, users are expected to create a SystemGroup allocator when setting a system group's rate manager. For details and sample code, please refer to https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/allocators-system-group.html

    This link is an overview of the allocators we currently have, https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/allocators-overview.html

    Thank you and have a good day!
     
  4. HBG-Mathieu

    HBG-Mathieu

    Joined:
    Feb 16, 2023
    Posts:
    59
    Ahhh, I never looked at the netcode samples (because I don't use it) ! I'm going to check it anyway then, thanks !


    No need to apologize, I was just sharing the information !
    Ok, so I did see all the links in fact, I wasn't sure if nothing more was hidding behind the dead links.
    And thanks a lot for the explanation, it made me realise that the main pupose is to help to manage allocation inside jobs, instead of trying to dispose in specific jobs or whatever. That makes sense but I couldn't figure out with the manual, so thanks !
     
    barbara-wang likes this.