Reputation: 125
I have several questions:
1) When I statically allocate array of 1 000 000 int, I got stack overflow error:
int temp1[48][48];
int im2 [1000000];
int step = 8;
int lcol, lrow;
....
Although, 1000000*sizeof(int)=4 000 000
< 4 Mb. And I have about 8 GB of RAM.
2) What happens when I use dynamical allocation (new and Malloc functions) and forget to delete my memory? Will my future compilations be affected by memory leakages from the past compilations?
3) If yes, how can I fix it? Should I close and open visual studio, or I have to reboot my PC?
4) If I use dynamical allocations with corresponding delete operations correctly, but I work in debug mode (step by step compilation) and I compiled "new" command and didn't compile "delete" command, will there be a memory leakage?
Upvotes: 1
Views: 99
Reputation: 141554
Based on your symptoms , these lines are inside a function:
int temp1[48][48];
int im2 [1000000];
so they are not static. The C term for this sort of storage is automatic. You could make them static by using the static
keyword, which will make them not subject to stack overflow. It is not required to use malloc
here, although that is an option.
Upvotes: 1
Reputation: 182761
It's not unusual for platforms to have limitations on stack size.
On every modern platform you are likely to use, a process' address space ceases to exist as soon as it terminates. So there's no need to do anything about leaks of allocated address space, backed or unbacked, across process termination. The address space ceases to exist because it belongs to the process.
If you allocate without deleting, that address space will be wasted until the program terminates. In significant amounts, this can create performance problems and resource consumption problems.
Upvotes: 5