I've been trying to figure out when things get allocated on stack and I can't figure out how would you make array (or rather values in it) get allocated on stack;
in this example:
public void foo()
{
int bar[] = new int [10];
}
10 int structs would be allocated on the the heap, only pointer to them would be on stack, correct?
How would one make fixed size array to go on stack? What if I'm using stucts I defined?
What if I want array size passed as parameter to function?
As far as I understand there should be no problem to get array of arbitrary size on stack when function is called, if size is known when function is called.
Should I even be bothered by this? As far as I understand getting this fixed size array on stack would improve performance, because no heap allocation is done.
Should I be bothered by this?
probably not. It sounds like you're prematurely optimizing and thinking at too low of a level. – Joylessstackalloc
can be used for forcing a stack allocation of a certain number of bytes. It has its uses but you should be very sure you need it - most programs (especially line-of-business applications) don't need it. – Ardys