Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

[ Create a new account ]

Com2Kid (142006)

Com2Kid
  com2kidSPAMLESS@gmail.com
http://com2kid.wordpress.com/
AOL IM: com2kid (Add Buddy, Send Message)
Yahoo! ID: com2kid (Add User, Send Message)

Knowledge is an end to itself.
-
Like fantasy stories? Like music? You'll love Sable*! [mp3.com] (just pimping an artist) -
Need some high quality low polygon count 3d models? Visit my webpage [netfirms.com] (now up!) Free work for Open Source Programers! Journal [slashdot.org]

Journal of Com2Kid (142006)

Great moments in programming stupidity

[ #172781 ]
Friday May 25 2007, @06:34AM
User Journal
I am taking this Programming Competitions Preparations class. The problems are all horribly unrealistic and not represenative of Software Engineering at all, but then again, they are not really meant to be.

Problems are solved in a two hour period in a team, typically of 3-5 students.

Well, my team realized that today's problem could be easily solved if we plotted points on a grid.

Hmm, lets see now. The largest a coordinate can be is 40,000. Ok simple, declare a 40,000 X 40,000 array of booleans.

Oh, too large for the stack, ok, declare it on the heap.

Umm, hey why is this taking so long.

Wait, what is 40k * 40k again? Oh crap.

Just for laughs, open up Task Manager and hit "Run", watch the VM usage go up to 1.90GB. Hey, look, I can see principles from my Operating Systems class in action! Awesome!

Hey, wait, did Windows just swap everything out to disk? Wow, everything is taking awhile to get back in order.

So, who here can quickly implement a sparse matrix?

To be fair, such stupidities only occure because there is a hard time limit. Normally I would never hard code in an array of anything near that size. Indeed, I do not know of any students here who would ever hard code in an array and say "That should be enough".
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login
Loading... please wait.
  • calloc a 200 meg chunk of memory and use that, instead of an array. Calculate the offset into the memory yourself (actually, you'll need less than 200 meg, 200,000,000 bytes to be exact).

    40,000 x 40,000 / 8 = 200,000,000 bytes.

    Or if you're got a spare

    • Because the code is compiled and tested on a remote machine of which we have no clue about the specs for, not to mention it has the be pure standards conformant C++ since we also don't know which compiler is being used either!

      Not to mention that sparse arr
      • My way would work with any standards-compliant C compiler - no need for C++. It would also have the advantage of not generating a 2 gig swap file, and of allowing up to 40,00x40,000 data points to be stored. Saving to disk would be as simple as writing out