Home performance and memory optimization (class vs struct)
Reply: 0

performance and memory optimization (class vs struct)

user1061
1#
user1061 Published in May 23, 2018, 4:49 pm

I am starting to work on a polygon library, whose side are bezier curves. The basic don't quite work yet so I can't really write stress / performance test program yet. nor show much code.

At any rate I have classes like that

public class BezierFragment
{
    Point2D[] controlPoints; // length: 2, 3 or 4
}
public struct Point2D { public double X, Y; }

But I am wondering whether I should instead use struct (for less heap allocation and more stack copies)

public struct BezierFragment
{
    byte order; // 2, 3, or 4
    Point2D p0, p1, p2, p3;
}
public struct Point2D { public double X, Y; }

The later is much easier on the memory management, but might require more copy (of 65 bytes) struct. I wonder which one would be best. How would I figure out the best option?

The (possible) memory management issues of the first choice might only be apparent when lots of Point2D[] array are saved in generation 2 memory pool and then destroyed...

Any tip?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311826 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO