Computer Science Canada CCC- (Java) Memory Constraints? |
Author: | ihsh [ Fri Feb 24, 2012 8:47 pm ] |
Post subject: | CCC- (Java) Memory Constraints? |
When I was testing my solution for problem five in CCC seniors 2009 (Wireless), I found out that my program would get an OutOfMemory Exception whenever it tries to create a 30000*1000 integer array (which is absolutely necessary for the problem). After some trial-and-error, I found out that my java problem could only handle about an integer array of size 15 million , which I think is just less than 60 mb (and this seems quite low, doesn't it)? Then I looked at the solutions provided by the unofficial solutions page. They also use 30000 by 1000 arrays, and they use the same IDE as I do (Ready to Program by Holts Software, which I think uses an IBM compiler), but apparently the people who coded them had no trouble running the programs against the larger test cases. So is this just a problem with my computer's memory allocation? Or...? I am a bit concerned about this kind of problem arising in the CCC-- what if a similar question appears, and for whatever reason my teacher's marking computer can't "handle" the memory? Also, normally how how much memory is allocated to a single java program? Thanks. |
Author: | tyuo9980 [ Fri Feb 24, 2012 9:31 pm ] |
Post subject: | Re: CCC- (Java) Memory Constraints? |
i think u can increase the memory in the preferences. it doesnt increase stack size tho. |
Author: | ihsh [ Fri Feb 24, 2012 9:45 pm ] |
Post subject: | RE:CCC- (Java) Memory Constraints? |
Wow thanks! Now I just have to make sure that I inform my teacher about it if there is a question that requires large memory use. |
Author: | crossley7 [ Fri Feb 24, 2012 10:13 pm ] |
Post subject: | RE:CCC- (Java) Memory Constraints? |
It probably has something to do with your computer. I was having similar issues with C++ for a while and recently it fixed the issue randomly |
Author: | coolgod [ Sat Feb 25, 2012 12:07 am ] |
Post subject: | Re: CCC- (Java) Memory Constraints? |
don't think c++ has the same issue. Java default heap size is pretty small, you can tweak in the compiler with some flag i forgot to set more. c/c++ has small stack size but dynamically allocating things can easily make huge arrays. |
Author: | ihsh [ Sat Feb 25, 2012 12:37 am ] |
Post subject: | RE:CCC- (Java) Memory Constraints? |
Thanks for all your replies. Just one more question (I don't want to create too many topics...) : does anyone know whether it is allowed to view the Java Documentation during the Canadian Computing Competition? Thanks again. |
Author: | bbi5291 [ Sat Feb 25, 2012 2:28 am ] |
Post subject: | Re: CCC- (Java) Memory Constraints? |
Quote: When I was testing my solution for problem five in CCC seniors 2009 (Wireless), I found out that my program would get an OutOfMemory Exception whenever it tries to create a 30000*1000 integer array (which is absolutely necessary for the problem). Not quite. Hanson Wang, the top finisher that year, wrote a solution using coordinate compression. It's certainly true that the solution with the huge array is easier, though.
Quote: Then I looked at the solutions provided by the unofficial solutions page. They also use 30000 by 1000 arrays, and they use the same IDE as I do (Ready to Program by Holts Software, which I think uses an IBM compiler), but apparently the people who coded them had no trouble running the programs against the larger test cases. Actually, the solution that says it's by me was written in C++. I don't know why the guy thought it needed to be converted to Java.
Quote: Just one more question (I don't want to create too many topics...) : does anyone know whether it is allowed to view the Java Documentation during the Canadian Computing Competition? AFAIK this is not allowed. The rules say:
Quote: Books and written materials are allowed. Any machine-readable materials ... are not allowed. Evidently, you are however allowed to print out an arbitrary number of pages of documentation and bring them with you to the contest.
Also, a note regarding memory in C++: automatic variables, that is, the ones that are declared inside functions neither statically nor dynamically, are allocated on the stack, and Windows has an absurdly small default stack size. I recommend that you declare all your large arrays statically during the contest. |
Author: | mirhagk [ Sat Feb 25, 2012 11:33 am ] |
Post subject: | RE:CCC- (Java) Memory Constraints? |
This is semi-related, I tried running a test to see how much memory I can allocate (basically create 2D jagged array, and slowly fill it with 4096 arrays of 64 bit ints until I get an exception). I kept getting 1.6GB as the maximum until I realized that 32 bit programs only get a small amount of space, so I changed the target to 64-bit and I hit 28GB lol (my computer kind of freaked out then, but that's okay). So basically my question is, can I target 64-bit and use 28GB of memory? (assuming my teacher has a 64-bit machine with enough hard drive space) |
Author: | coolgod [ Sat Feb 25, 2012 11:35 am ] |
Post subject: | Re: CCC- (Java) Memory Constraints? |
just wondering where does it say physical written materials are allowed? I've been trying to find that page for a while now. Can you please link me to it>? And also is runtime restriction 1 minute? |
Author: | crossley7 [ Sat Feb 25, 2012 11:39 am ] |
Post subject: | RE:CCC- (Java) Memory Constraints? |
Thanks for that advice. I will keep it in mind while I do the competition. And also, can you think of a single program that would take more than 1.6GB of memory that might be put in a contest? The size of an array to take up that much space would be ridiculous and I'm doubtful that people writing the CCC would send that type of problem although I could be wrong |
Author: | mirhagk [ Sat Feb 25, 2012 11:55 am ] |
Post subject: | RE:CCC- (Java) Memory Constraints? |
Actually the last 2 senior problems are usually problems that if you don't do correctly will take a ridiculous amount of memory, ie 28 GB. |
Author: | md [ Sat Feb 25, 2012 12:18 pm ] |
Post subject: | Re: RE:CCC- (Java) Memory Constraints? |
mirhagk @ 2012-02-25, 11:33 am wrote: This is semi-related, I tried running a test to see how much memory I can allocate (basically create 2D jagged array, and slowly fill it with 4096 arrays of 64 bit ints until I get an exception).
I kept getting 1.6GB as the maximum until I realized that 32 bit programs only get a small amount of space, so I changed the target to 64-bit and I hit 28GB lol (my computer kind of freaked out then, but that's okay). So basically my question is, can I target 64-bit and use 28GB of memory? (assuming my teacher has a 64-bit machine with enough hard drive space) There is absolutely no reason you should be using 28GB of memory for anything in the CCC... but targeting 64 bit is probably a good idea. Also, this no documentation thing is retarded - being able to quickly find, read, and understand documentation is kinda how you master (and to a certain extent) use standard libraries. |
Author: | ihsh [ Sat Feb 25, 2012 12:42 pm ] |
Post subject: | Re: CCC- (Java) Memory Constraints? |
Quote: Evidently, you are however allowed to print out an arbitrary number of pages of documentation and bring them with you to the contest.
Okay thanks, so I will just print out the Line2D class, in case that some geometry problems come up... I may also print out the explanations for Dijkstra's algorithm, as well as the constructs for regular expressions. coolgod @ Sat Feb 25, 2012 11:35 am wrote: just wondering where does it say physical written materials are allowed? I've been trying to find that page for a while now. Can you please link me to it>? And also is runtime restriction 1 minute?
It's part of the student instructions, which can be found on the second page of the CCC packages (e.g., 2011). |
Author: | mirhagk [ Sat Feb 25, 2012 12:50 pm ] |
Post subject: | Re: RE:CCC- (Java) Memory Constraints? |
md @ Sat Feb 25, 2012 12:18 pm wrote: Also, this no documentation thing is retarded - being able to quickly find, read, and understand documentation is kinda how you master (and to a certain extent) use standard libraries.
Not if you use an IDE that has something similar to Visual studios summary tags. Those things make using standard libraries so much easier because you don't have to look up everything in the documentation, and can even use functions that you've never even heard of before. |