I have a standard Web API application. Let's assume that in an action I would like to return response like this:
public IHttpActionResult GetSomething()
{
var model = new Domain.OutcomingModels.Action[1];
return Ok(model);
}
For model
object I could specify to be a class
or a struct
. From my point of view there are no reasons to prefer struct
over class
, concerning performance.
The app will handle millions of client's requests per seconds. Things that I'm concerned about:
- Time to create class over struct
- Memory consumption on class or struct
- Time to pass the object to a method that will return IHttpActionResult
- Memory consumption to pass the object to such method
- Time on serialization
- Possible issues with heap defragmentation
- Possible issues with garbage collector in general
Am I right?
The question is not about general difference between classes and structures. It is about using them with the methods like Ok
or BadRequest
that will convert C# objects to serialized objects. I'm asking about possible caveats.