I was wondering if anyone can tell me what should a program do if there is a memory allocation error(besides exit the program). If there is other memory allocated should that be freed first? or should the program just terminate where it is?
Also I was wondering if anyone can tell me why my system doesn't show any memory loss if I dont use free. I ran a test program that basically was like this:
Now I was running Nortons System doctor at the same time I ran this program. My system was at 68 megs free, when I run the program it drops down to 19 megs free or something like that which is normal for this program. Now when the program finishes, my system reports 68 megs free or so again . What gives? I would think that nortons would show this memory as being tied up. I also used windows xp system tools and it gives me the same results. Now what I think is going on is that the memory is tied up but windows knows that this memory can be used and reports it back as being free. The reasoning behind this conclusion is that I ran this program about 15 times, and after I was done I tried to open windows explorer and it took over a minute to open(I am on a 1 gig with 128 megs of ram so this isn't normal) but my free ram was showing 70 megs or so. What I am thinking took so long was window trying to get back this memory that it told me was free. Am I anywhere near being right about this? or even kinda right(somehow in my twisted logic)Code:int main(int argv, char *argc[]) { int *ptr = NULL; int i; for(i=0;i<2;i++) { if(!(ptr = malloc(10000000 * sizeof(int)))) printf("Memory error"); } return(0); }