Monday, July 27, 2009

Under what circumstances would parallel arrays be useful?

Under what circumstances would parallel arrays be useful in C# ?

Under what circumstances would parallel arrays be useful?
"Parallel arrays" are essentially a hacked form of an array of objects. For example, you can either have an array of object that contains a float and an int, or you can have two arrays, one of float and one of int.





You only want to do this when there is little or no behavior associated with the object. In other words, you just have associated values but no methods that combine them or rely on them. In addition, this is only beneficial when you have a large array of these objects.





The advantages of the parallel arrays include no memory overhead for each object in the array and less compute time required to allocate/collect each of the objects.





In general, if you find that you need to use parallel arrays, you should still define the class for the object, as well as a class for the collection of the objects. The latter class should hide the parallel array implementation, as well as utilize the business logic of the object internally. This may require exposing the field-wise business logic from the object to at least the collection-of-object class.





Good luck!
Reply:Any time you want to speed up a process.


No comments:

Post a Comment