Cannot `stackalloc JobHandle[]`
thygrrr opened this issue · 2 comments
Even though JobHandle is a struct, I cannot seem to be allowed to stackalloc an array of them, which makes allocation free scheduling of jobs from within a loop of unknown runtime count very cumbersome (borderline impossible).
It would be extremely convenient to be able to do this to get the ability to directly and synchronously schedule and then complete workloads without allocating or messing around with a List or something like that.
It would also help to combine job dependencies as these jobs are being scheduled in parallel. As far as the package's api goes, that requires some sort of Span to be passed in. But assembling that span in memory is impossible without going through another type like System.Array or System.Collections.Generic.List.
... but it is a struct. And that totally works with other structs:
What am I getting wrong here? :)
I tried to work with a list with pre-reserved capacity, but I can't even submit a List to Scheduler.CombineDependencies. So there's no chance (without juggling array indices and counting jobs?) to track dependencies as they accrue?
Thanks for pointing this out!
@LilithSilver What do you think about this one?
To use stackalloc, a struct must be "pure", i.e. contain no managed type references. Unfortunately, the JobHandle contains a reference to its associated Job.
For now, pre-allocate and store a List, and use CollectionsMarshall.AsSpan(list), as discussed here: https://stackoverflow.com/a/60514418/2779909
I agree that this would be super convenient though... I will look into associating an ID to a Job instead of storing a class reference for scheduling purposes. That would add some overhead to the scheduler but maybe that's OK.
Thanks for pointing this out!