#DataArray Structure
1 messages · Page 1 of 1 (latest)
Can someone help me with this problem?
I am switching form a quadtree to a one dimentional data structure, eventho I would like not to have to itterate throught the entire array, if possible which is why I m making a list of written memory but I seem to enconter a simmilar problem again
pls ping
@finite mason pls explain what your issue is codewise. It is somewhat hard to get your issue just be looking at those arrays and some comments you put there.
There is no code, I am working on an idea
I want to make a one dimentional array, which stores structs
My first Idea would be that I would have one stack for the avalable memory and the array which stores the structs
At the start the stack with the memory indexes where there is no struct will be full to it s max size for example numbers form 0 to 1023
Then if a struct gets added to the array it asks the avalableMemory stack for an avalable spot, which in this case will be whatever number is at index 1023 of the stack, then the struct will get put into the memory Index at [1023]
But now my issue was that if I the array was lets say a size of 1024, and only one struct of those 1024 is set, then I would have to itterate trough 1024 elements instead of one
And Im looking for a solution for this
@narrow trench
What do you need this for
for managing a huge ammount of structs using an array instead of a quadtree hirachy, and I want to be able to use the Unity Job system as well
@daring mountain
What's the reason for using it instead of the
quadtree hirachy
If you use job system, you are tied to a NativeList, right?
As the NativeList is just pointers to memory, if I am correct, I guess you have to iterate through it anyway to see what spot is empty. Not sure, what you expect to make it simpler.
by keeping track of which index is empty or not
How do you know an index is empty without iterating? If you know when you dispose it, you can of course have a second array holding only the indexes of the objects, but I do not think thats helping a lot
I actually torught that this was the solution, unitill I realized the problem, which I pointed out on the last page
If a struct gets removed from the NativeArray, it would have to remove the item, in the array at the index, which holds it s index in the NativeArray, which means that first I would have to itterate trought it again, and furthermore even shift the array of every item that was above that by one, which seems like too much work
so looping trough it is probably the best solution?
I guess so. I mean if you store the indexes, you can always just use that array to add to the list AtIndex(); and do not have to iterate. So for your tempList[0] you just use the first ones int to AddAt(tempList[0]) until its empty? not sure thats helping a lot, but worht a try if your numbers are high and performance is actually measurable
that s a good Idea but when I add and remove indexes all the time that would kinda remove the purpose of my idea, but what if I had multiple native arrays.
I start with 1 native array and if that one is filled I make a new one and if the array is empty I remove it
So creating arrays all the time when only one index hits the threshold of the list size? not sure, thats a good idea
And if you have like one native array, adding up to lets say 1024 items and you create a new one, whats happening to like 500 disposed objects of the first one? are they just empty pointers now but still counting into the length of the array?
By the disposed objects, do you mean the objects that will later be disposed inside the Arrays[0]?
If you delete/dispose objects of your native array, are they being removed at some point in the array index or is it just holding an empty pointer?
they will get deleted, but the index of where they got deleted will get added to the stack of avalable array indexes
So if you delete one item in a native array at index 5, index 5 is empty or completely replaced by index (former) 6? and so on