#Dynamic list of NativeArrays? [Solved]

1 messages · Page 1 of 1 (latest)

rose garnet
#

I want to create a System that holds reference to a dynamic (more like configurable for the baking process) number of NativeArrays.

Imagine n-instances of NativeArrays. My System will spawn x-number of jobs that each take in two of those NativeArrays - looping over one of the Arrays for the actual Job.

Example:

var na1 = new NativeArray<float3>(count1, Allocator.Persistent);
var na2 = new NativeArray<float3>(count2, Allocator.Persistent);
...
var nan = new NativeArray<float3>(countn, Allocator.Persistent);

Since i don't know the number of lists(arrays) i need i was thinking of holding them in some kind of DynamicBuffer or just a HashMap (n - the number being the key and the NativeArray the value). Is that a good idea - can i instead make a NativeArray of NativeArrays?
Would i be better off just making one big NativeArray (merging all the lists together and keeping a pointer/index-number where each list starts and ends?)

As i mentioned, the job will take two lists and then iterate/batch items of the first array to compare against the second.

Am i missing something - is there a better way - or will my ideas even work - will it be suboptimal from an ECS perspective?

rose garnet
#

Upon thinking further, i would need to recreate these NativeArrays each Update - perhaps i can create a query in the startup and then create the array in the update...

I have a lot of the same IComponentData d I just want to pull out a float3 LocalLocation but group each list by an int Key.

So one job iterates over Key=1 against Key=2, another job perhaps also iterates over Key=1 against Key=10 , etc... Each set has a slight variation (float) defined for each set of lists

scarlet gate
#

You can't make an Nativearray of Nativearrays' but you can make an UnsafeList within Nativearrays

#

or you can use the other unsafe types, but you will have to take care of the safety yourself hence them being unsafe

crimson scaffold
#

with 1.0 you can nest native collections

#

just beware that safety doesn't work properly with this

scarlet gate
#

oh what leahWTF

crimson scaffold
#

yeah, they got rid of managed safety handle

scarlet gate
#

so many changes, well that is cool

rose garnet
crimson scaffold
#

so if you plan to pass your array of arrays in a job

#

beware that no errors will pop on unsafe situation

rose garnet
#

Ahh like this - no i will pluck out two arrays of the parent array and pass those to the jobs

#

it's ReadOnly data that i pass anyways - i will add a result to a dynamic array associated with the entities

zealous garnet
#

Maybe a NativeMultiHashMap would work for you?

glad blaze
rose garnet
#

I'll still only use the NativeMultiHashMap in the System - then pass the two NativeArrays of float3 to the jobs

rose garnet
#

Am I missing something with the NativeMultiHashMap - there is no Get(TKey key) method - i can get it to return a NativeArray of my NativeArrays but then i gained nothing. How can it be a HashMap if there is no direct lookup on the key? Perhaps it's a .net/c# concept that then it's called a Lookup then - but why would i care if the underlying structure is a hashmap if i can't do a lookup on the key?

#

Sorry for spamming my thread, but it just dawned on me that there is a Multi in the name, hence the get will return a collection of multiple entries with the same name - guess i'll go look at NativeHashMap instead 😄

zealous garnet
#

You basically can iterate through the entries of a hash (via an enumerator), exactly. So essentially it is a hashmap that stores collections / arrays as entries. That is why I suggested it (because I thought that is what you wanted)

rose garnet
#

Thanks everyone - I ended up using the NativeHashMap - it has a TryGetValue(TKey key) which is ecatly what i needed 🙂