I was watching a video that said: on Windows the size of the stack allocated in virtual memory, per process, is 1mb. I wasn't sure if it was correct, but anyway ...
So I was thinking; What happens if you declare a local variable within a function with a size that exceeds 1MB? Let's say and array of 1 byte char's whos size is around 2MB:
char oops[2000000];
There isn't enough space on the stack (if only 1mb is allocated for the stack) to reserve the required memory for the char array. What happens? Would this raise some memory exception?
And if infact an exception would be raised, the way around this would to be to declare the variable on the heap with malloc
(deleting it at the end of the function)?
I would test, except I'm not at a computer.
Aucun commentaire:
Enregistrer un commentaire