Monday 21 March 2016

c# - Are these method parameters stored on stack or heap?

I've read countless articles where class and object instance variables are stored on the heap, while local and method variables generally are stored on the stack.



But what about method parameters that are objects?



private void myMethod (int a, myObject b)
{

bool c = (a > 0 && b.myCounter < 0 ? true : false);
//do some more work
}

//Are both a & b stored in the stack? Or is "a" in the stack and "b" on the heap?


EDIT/UPDATE: "b" is currently a class, not a struct. It has approximately 20 properties with some properties determined by a boolean operation of properties contained within it (similar to how "c" is done in the code example), so would consider refactoring it into a struct if that makes more sense.



Looking at such micro-optimizations as this is a real-time and resource-performance critical financial application.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...