Hello

Note: Please answer only if you know how to solve from this kind of error

Ok, what happening is, I am getting a runtime error(SIGSEGV), when I am trying to post my codes on online C competitions.
Did a little research, and found that its mainly related to either using too much memory ( am sure my maximum array elements are "unsinged int range" looped 1000 times ..
so am not using too much memory, maximumI suppose would go till 10MB and the contest limits me to use till 64MB memory.
Ok, second case is, I can have a Memory out of bound. Segmentation error, which usually happens..

so What I did was.. I installed MinGW[ earlier I compiled in Dev-cpp] and then used the gdb error debugging method for segmentation error.. but, what happened is , my debugging gave me that the program EXITED NORMALLY in the end, something like that.. which was clearly the fact that its not a segmentation error..

ok...


Am attaching my code below.. well if u wanna read... don't worry if u see such a long code.. leave the calculation part, trust me, there is nothing wrong, am getting the correct output on my Dev-cpp and MinGW -gcc( gcc Mycode.c -Werror)..

well this is what I doubt...
long insigned int -> range is 0 to 2^31-1 (2147483647).
and I used K as "long unsigned int" to enter a limit...
after that I made an array xl(say, actually I made 4, lets take one of them )
and wrote
xl=(long unsigned int *)malloc((k)*sizeof(long unsigned int));
so it would make an array of length 'K' and if the user inputs 2^30 which is perfectly valid since K is long unsigned int type, so, it would make an array of 1,073,741,824 X 4(bytes for each)= 4096MB means 4GB ...
My system has 16GB ram.. so is this the memory OUT OF BOUND problem..

NOTE: if u think this is, convince me, because I installed a virtual WinXP on VMWare, then limited the RAM size to 512MB and ran, and it ran well, but I never took input so big..

Right now, I tried with K value as 123456789 and error came.. windows errors.. I suppose, this is the problem..
Ok so If I was wrong above in debugging.. tell me, guys.. how would I take the input.. cause I have to take array of size K which is an "unsigned long int" size...

1process I came up with is..: I would save value of k in k1. then would run for each 1000 values at a time... then free up mem, again do it for next thousand... like that..

HELP HELP.. any solution..
Attached Files
File Type: txt My code.txt (7.2 KB, 6 views)