what is the memory overhead on the stack and heap of A versus B
A:
private string TestA() { string a = _builder.Build(); return a; }
B:
private string TestB() { return _builder.Build(); }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
re the efficiency question; the two are identical, and in release mode will be reduced to the same thing. Either way,
stringis a reference-type, so thestringitself is always on the heap. The only thing on the stack would be the reference to thestring– a few bytes (no matter the string length).‘do all local variables go on the stack’: no; there are two exceptions:
yield returnetc)In both cases, there is a compiler generated class behind the scenes:
is similar to:
Hence
iis on an object, hence on the heap.Iterator blocks work in a similar way, but with the state machine.