We have a set of locations in our product where BigInteger is required, as the numbers can be quite long. However, in more than 90% of cases, they are actually not so long and can be easily arranged over time.
Looking at the implementation of BigInteger, it would be nice to spend time using BigInteger, where Long is enough.
Would it be prudent to create an interface that has functions like BigInteger (division, multiplication, etc.), and this will be implemented by the BigInteger child class and the class that wraps Long? Something like:
Interface: EfficientBigInteger Class 1: MyBigInteger extends BigInteger imlpements EfficientBigInteger Class 2: MyLong implements EfficientBigInteger (this will contain a Long, as we cannot extend the Long class)
Perhaps we are in the wrong direction?
Thanks Yon
UPDATE: These objects (Long or BigInteger) are stored in memory for quite some time, since they help us identify the problematic behavior of the systems with which we interact. Therefore, a memory issue can be a problem. This is a problem that we are trying to avoid. The BigInteger class has several fields (signum, mag array, bitcount, etc. etc.), which are approximately twice as large as the class that encapsulates Long (taking into account the memory costs associated with the presence of the object in the first place ) This means that we double what we use.
Yon
source share