Hi Matt,
Speaking of Points, Lines, Rectangles and Polygons. Here is what I found
based on my experience.
Points and Rectangles should be *structures*
Lines and polygons should be *classes*
Why?
Because points and rectangles are like primitive types for any graphics. A
lot of temporary objects of them are created passed as a function arguments
mostly by value, copy between each other and. arithmetic-like operation +/-
may make sense for them. That's all calls for *structure*. Otherwise you
will pollute the heap with small chunks of garbage.
At the other hand the very often reside in collections and as a fields of
classes, which may makes you think that it might be better to make them
classes.
Keep in mind that when value types are fileds of classes there is no boxing.
Structure's data is part of the objects data in the managed heap. About
collections... Don't forged that when value type objects are kept in array
they are in unboxed state so you don't have to worry about boxing/unboxing.
Thus, you can make your own strongly-typed collection classes and use
internaly arrays as a storage. This will solve your problem with
boxing/unboxing.
Lines and polygons at the other hand may be very big and heavy objects
usually you don create them as a local variables and don't pass them
by-value. Classes, I believe, are more appropriate for them.
--
HTH
B\rgds
100 [C# MVP]
"MattAhsworth" <Ma**********@hotmail-dot-com.no-spam.invalid> wrote in
message news:40********@Usenet.com...
I'm develpoing a mapping app and want to store the point data that
makes up lines, points and polygons efficiently.
Am I better off using unsafe C# and creating structs to hold the data
on the stack (100K plus points total) or create classes for all the
data and put up with the overhead of boxing/unboxing?
Is there some middle ground - perhaps an array of structs containing
point data to represent a line wrapped in a class? - if I do that
will the data still be on the stack or will putting it in an array or
class make it an object and force it onto the heap.
Performance is a big factor.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com