Search Unity

Is there any way to increase stack size of Job system

Discussion in 'C# Job System' started by shiqiang_vts, Nov 19, 2021.

  1. shiqiang_vts

    shiqiang_vts

    Joined:
    Jun 12, 2019
    Posts:
    49
    I have a recursive function in my job, it will consume a lot of stack memory.

    Now the default stack size of Job system is too small, it will cause out of memory.

    Is there any way to increase it in Unity?

    Thanks.
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,648
    From what I've read in a short time, Windows has a default stack size of 1MB (it is dependent on your OS). In order to change this, you can modify your PE Header of your Executable (???) or you can create a new thread, which can take stack size as one of its overloaded constructors.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    A better place to ask this would be the DOTS forums.

    I can move your post there if you like.
     
  4. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    There is a "Memory Settings" page in the project settings. It has many entries so you may want to look up what every one does before you change it mindlessly ;). By increasing settings you just move the problem farther away but don't solve it.
    Also keep in mind that every recursion can be done with loops too. So there maybe is no need for fiddling with these settings if you rearrange your algorithm. And as far as I know recursion is not ideal for threading either. It should be more arranged like "batch processing" so doing the same operation on an array of data and not "jumping around".
     
  5. shiqiang_vts

    shiqiang_vts

    Joined:
    Jun 12, 2019
    Posts:
    49
    Thanks for your advice.
    DOTS forums is better.
     
  6. shiqiang_vts

    shiqiang_vts

    Joined:
    Jun 12, 2019
    Posts:
    49
    Thanks for your advice.
    If there is no way to increase stack memory size of job system, I will try using a new thread.
     
  7. shiqiang_vts

    shiqiang_vts

    Joined:
    Jun 12, 2019
    Posts:
    49
    Thanks @exiguous
    I didn't find "Memory Settings" page in the project settings. Could you provide more details.
    upload_2021-11-22_10-27-9.png
     
  8. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    This is how it looks for me. I'm on Unity 2021.2.3f1. Maybe this is also added from an installed package? I don't know.
     

    Attached Files: