News for hackers. Stuff that matters.
Re:Nearly All Binary Searches and Mergesorts Are Broken by poincaredisk on Saturday January 11, 2025 @07:24AM (#42665414)
I'm not a Java programmer, but how would you load of a 1GB file into memory? I assume read returns some kind of an array.

Also big arrays being (supposedly) a coffeee smell doesn't mean that code handling them improperly is not buggy.

Re:Nearly All Binary Searches and Mergesorts Are Broken by angus_gh on Saturday January 11, 2025 @08:00AM (#42665565)
Java's arrays use a signed 32-bit int as their length, so the longest they can be is about 2 billion elements.

If your code has arrays over a billion elements, then it will fall over the moment someone inputs slightly larger data

Re:Nearly All Binary Searches and Mergesorts Are Broken by aardvark179 on Saturday January 11, 2025 @09:04AM (#42665943)
If you really needed it in memory you’d use one of the file APIs that will map it and present a direct byte buffer view over that memory.

Those APIs use long as their offset unlike the 32 ints used by arrays, and would avoid having to copy the data into some other object.

There has been some discussion over the years about how arrays could be changed in the JVM to support longer lengths, but doing so without breaking existing code and while providing truly useful functionality without providing obvious footguns isn’t as easy as you might think.