Hey guys!I want to store in 2d array binary numbers with 10 bits.I want to store 10.000.000 numbers but when i try this,my programm prints me the message error and programm crashes. i did not use dynamic memory.I create this array int[10.000.000].
Can you help how can fix the problem??
What's dynamic memory? What error did you suffer? Why did you say you wanted binary numbers? All numbers are stored in binary on a computer. Have you posted the exact code you used? What you had in your text won't compile.
You are allocating space for 10 million arrays of size 10. That means this array can store 100 million integers. At 32 bytes each, you are allocating 3.2 GB to store these integers. I believe the maximum heap space a Java program can consume by default is around 2 GB, so you're probably running out of memory.
You're going to have to design this in such a way where you don't consume that much memory. Or use a ByteBuffer or something similar so that it doesn't get allocated to the heap.
Zachary Griggs wrote:. . . At 32 bytes each . . . .
That's 32 bits each, not bytes. But each array occupies something in the region of 20 bytes over and above its contents. That memory consumption is implementation dependent and probably slightly more on a 64‑bit machine than an old 32‑bit machine. So you can add 10,000,001 × about 20 bytes to your 10⁹ ints.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop