Hello i am trying to figure out how does stackalloc
work.So coming from C/C++
from my knowledge (limited) you can not allocate memory on the stack dynamically like in here:
C/C++
example:
void Allocate(int length){
int vector[length]; //wont work
}
Then C#
comes into play and you can do it with stackalloc
:
void Allocate(int length){
int []vector=stackalloc int [length];
}
Isn't the whole point of allocating on the stack
to know at compile-time
or precompile-time
(macros
etc) what size will the array have?How does C# manage this "magic"
? How will the stack-frame be created?
alloca
.alloca
in C.