Skip to content

Instantly share code, notes, and snippets.

@jeffvella
Last active February 25, 2020 02:10
Show Gist options
  • Select an option

  • Save jeffvella/e7a2b912cded1fb52d662b60358003c9 to your computer and use it in GitHub Desktop.

Select an option

Save jeffvella/e7a2b912cded1fb52d662b60358003c9 to your computer and use it in GitHub Desktop.
:D
int count;
int* countPtr = &count;
NativeKeyValueArrays<int, UnsafeEventBatch> pairsMaster = default;
NativeArray<Entity> entitiesMaster = default;
var pairsPtr = UnsafeUtility.AddressOf(ref pairsMaster);
var entitiesPtr = UnsafeUtility.AddressOf(ref entitiesMaster);
var sw = Stopwatch.StartNew();
Job.WithCode(() =>
{
ref var pairs = ref UnsafeUtilityEx.AsRef<NativeKeyValueArrays<int, UnsafeEventBatch>>(pairsPtr);
ref var entities = ref UnsafeUtilityEx.AsRef<NativeArray<Entity>>(entitiesPtr);
pairs = map.GetKeyValueArrays(Allocator.Temp);
for (int i = 0; i < pairs.Keys.Length; i++)
{
var batchCount = pairs.Values[i].Queue.Count();
*countPtr += batchCount;
}
entities = new NativeArray<Entity>(*countPtr, Allocator.TempJob);
}).Run();
sw.Stop();
Debug.Log($"Time={sw.Elapsed.TotalMilliseconds:N4}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment