Today i was reading a SO thread about array and its memory allocation. And i found an answer which was neatly explained and i must say its excellent.
But after reading that answer, i got few more questions which i kept asking myself about what i just read. So far still i am unable to answer it myself nor able to google it up. Hence i require your kind help in explaining those questions to me.
- Why is array getting created on heap when every of its content is getting stored on stack? Just 2 avoid boxing in case of value types?
If above was true, then why array had 2 be created on heap first of all?
When he said in his answer new int[100] is actually getting created on heap, is 400 (100 * 4) bytes getting allocated on heap? If so, why? because all the values are getting stored on stack
- If 1000 item array is created, then how on earth stack is enough to be stored? I know 1 MB is the size of the stack allocated. but in this case it will exceed. So whats the funda??
Please feel free to add your own questions or more info if you may have to this.
Thanks