I'm asking for a project in C#, but I assume this question applies to other languages as well. I've heard that massive object creation and destruction causes massive overhead and performance issues. I'm wondering if I can get around this by simply using structs instead of objects.
Here is some facts that you must now about struct
and class
in C# :
struct
in C# is faster to create than a class
since it's allocated on the stack and not on the heapstruct
is a value type, class
is a reference type. So working with a reference type (passing it as parameter, copying it, ...) is much faster than working with the value type. see Difference between struct and classstruct
fields are fast to access than class
fields since they are allocated on the stackHere is some facts about how the GC works in .Net :
Knowing all of that and to be short, if you don't want your program to suffer from the GC work, you have to use reference types for objects that will live the longer in your program, and use value types for objects that will be used for a very short time and in a very localized scope.