Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the max. capacity of byte-Array?

Tags:

java

I made a JavaClass which is making addition, sub, mult. etc.

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

each number is stored in Byte-Array and 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 is not working if the number is bigger then (example: 999^999)

How i can solve this problem to make addition between much bigger numbers?

When the byte-Array reachs the 66.443 values, VM gives this error:

Caused by: java.lang.ClassNotFoundException. which is actually not the correct error-description.

well it means, if i have a byte-array with 66.443 values, the class cannot read correctly.

Solved: Used multidimensional-Byte Array to solve this problem.

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

only few seconds to make an addition between big numbers.

Thank you!

like image 822
Racooon Avatar asked Dec 21 '22 12:12

Racooon


2 Answers

A single method in Java is limited to 64KB of byte code. When you initialise an array in code it uses byte code to do this. This would limit the maximum size you can define an array to about this size.

If you have a large byte array of value I suggest you store it in an external file and load it at runtime. This way you can have a byte array of up to 2 GB. If you need more than this you need to have an array of arrays.

like image 112
Peter Lawrey Avatar answered Jan 06 '23 21:01

Peter Lawrey


What does your actual code look like? What error are you getting?

A Java byte array can hold up to 2^31-1 values, if there is that much contiguous memory available.

like image 25
Michael Borgwardt Avatar answered Jan 06 '23 22:01

Michael Borgwardt