TimoneUK
TimoneUK

Reputation: 31

Most efficient way of drawing a large array of rectangles

I have a general question.

I am currently building a silverlight application that requires the generation of a large amount of rectangle objects. An example scenario would be 25 x 25 x 128 (stored inside a rectangle[,,]). The rectangles appearance can change depending on the contents of an int array of the same size.

The rectangles are then drawn onto a canvas. The current layer can be changed so that you get a different group of rectangles (controlled by the "z" axis of the multidimensional array)

This might seem obvious so I apologise in advance if that's the case. But is it more efficient to generate all these rectangles inside a large rectangle[,,] in one operation or to generate each layer into a rectangle[,] as the user requests it?

Upvotes: 0

Views: 353

Answers (1)

CodeCaster
CodeCaster

Reputation: 151700

is it more efficient to generate all these rectangles inside a large rectangle[,,] in one operation or to generate each layer into a rectangle[,] as the user requests it?

That totally depends. You can do the benchmarking of that because you are building the application, we don't know what you do before and after and what you want to store.

I'd say: create a Layer class that holds its own Rectangle[,] reference, so you'll have all responsibilities in one place, then iterate through a List<Layer>. You can then store, retreive and edit individual layers while the other rectangles remain untouched.

This way you can also easily load one layer if required.

Upvotes: 1

Related Questions