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 How to use data structure such as linked list or tree in Jobs?

Discussion in 'Entity Component System' started by gyx920820, Jan 21, 2021.

  1. gyx920820

    gyx920820

    Joined:
    Oct 8, 2015
    Posts:
    35
    The reason of using jobs is that I don't want to calculate in main thread. But my logic needs linked list. How?

    Another question: What if I want to schedule some new jobs in one job?
     
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    938
    Obviously, linked list are not supported by job/burst.
    Either the existing native containers works for you (native array, native list, native queue or native stream, maybe blob asset if it's immutable) or they don't.
    If they don't you need to go back to the drawing board to rethink your problem in a multi threaded context.

    And you can't schedule a job for a job, that has always been a big no no and won't change.

    Maybe try to describe your problem here and see if anyone can hint you in the right direction.
    Using linked list in a job is not a problem to solve, it's a feature request that probably won't ever come.

    EDIT : if you just want single threaded non bursted (not main thread) there is always the "hack" of the GCHandle https://coffeebraingames.wordpress.com/2019/03/17/run-managed-code-in-unitys-job-system/ (but carefull about race condition, you'll have no check done by unity !)
     
    gyx920820 likes this.
  3. gyx920820

    gyx920820

    Joined:
    Oct 8, 2015
    Posts:
    35
    Thanks!
    I want to solve exact cover question, by using dancing links.
    I am considering using nativearray to simulate linked list.
     
  4. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    You can write a custom native container if the built in ones don't work for you. There's a good series of articles by Jackson Dunstan all about that subject - one happens to revolve around a NativeLinkedList: https://www.jacksondunstan.com/articles/4877

    That one is from a couple of years ago so you probably won't just be able to copy-paste, but if you poke around his other articles and check his repo you should be able to put it together.
     
    gyx920820 and WAYNGames like this.
  5. gyx920820

    gyx920820

    Joined:
    Oct 8, 2015
    Posts:
    35
    thanks a lot!
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,615
    I believe they're kept pretty up to date here: https://github.com/jacksondunstan/NativeCollections
    Huge range of custom containers.
     
    Sarkahn and DreamingImLatios like this.