Reputation: 114046
I need to store multi-dimensional data consisting of numbers in a manner thats easy to work with. I'm capturing data in real time (processing live video frames every 40ms/10ms), and once processed I would destroy and GC older data.
This data structure must be fast so it won't hit my overall app performance. The faster the better (my algorithms are pretty time consuming, from 1ms to 20ms and I will be reading / writing this data lots throughout my code).
What are my choices in terms of platform supported data structures? I'm using VS 2010. and .NET 4.
Upvotes: 1
Views: 1359
Reputation: 16513
The fastest way is probably:
array[x, y]
<=> array[x + y * columns]
)Of course, this is a generic answer, because the question is also pretty generic. Can't really go wrong with it, though.
Upvotes: 1
Reputation: 22859
Realtime or not, creating an object in .NET is pretty fast, so what about ConcurrentQueue+ tuples?
That way you can read / write thread-safe with pretty standard data structures. The following code took 3 seconds on my T500 inside Visual Studio with debugging on:
Stopwatch sw = Stopwatch.StartNew();
var q = new ConcurrentQueue<Tuple<int, int, int>>();
Enumerable.Range(0, 10000000).AsParallel().ForAll(i => q.Enqueue(Tuple.Create(i, i, i)));
Console.WriteLine(sw.ElapsedMilliseconds);
Console.ReadLine();
Funny enough, the non-parallel version is even faster.
Upvotes: 1
Reputation: 77349
How about a simple multidimensional array? That seems like the obvious and fastest choice.
Upvotes: 0