What is max. array byte capacity?

I created a JavaClass that creates the add-on, sub, mult. and etc.

And the numbers are similar (155 ^ 199 [+, -, /] 555 ^ 669 [+, -, /] ..... [+, -, *, /] x ^ n);

each number is stored in a byte array, and a byte array can contain max. 66.442

Example:

(byte) array = [1] [0] + [9] [0] = [1] [0] [0]

(byte) array = [9] [0] * [9] [0] = [1] [8] [0] [0]

My Class file does not work if the number is greater (example: 999 ^ 999)

How can I solve this problem to make an addition between much larger numbers?

When the byte array reaches 66.443, the VM gives this error:

Caused by: java.lang.ClassNotFoundException . which is not really the correct description of the error.

Well, this means that if I have a byte array with values ​​of 66.443, the class cannot read correctly.

Solved: A multidimensional byte array is used to solve this problem.

array {array, ... nth-array} [+, -, /] nth-array {array, ... nth-array}

just a few seconds to make an addition between large numbers.

Thank!

+3
source share
5 answers

Each array can contain a maximum Integer.MAX_VALUE. If it falls, I think you see OutOfMemoryError. Fix this by running java vm with lots of heap:

 java -Xmx1024M  <...>

(example gives 1024 megabytes of heap)


java.lang.ClassNotFoundException , - , ( , java..). java.

:

. , , ClassBigMath . ClassBigMath.class .

, Java , , . :

  • ,
  • Class.forName("MyClass")
+2

? ?

Java 2 ^ 31-1 , .

+2

Java 64 . , . , .

, . , 2 . , .

+2

java.math.BigInteger - . , ?

+1

The maximum array size in Java is set by Integer.MAX_VALUE . These are 2 ^ 31-1 elements. You can get OOM exceptions for less if not enough memory. Also, for what you are doing, you can look at the BigInteger class . It seems you are doing your math in some form of decimal representation, which is not very memory efficient.

0
source

All Articles