I am trying to find a solution/workaround for slicing extremely large arrays without creating new copies. Here is my problem.
Suppose I have a large array of double/int of size 100 million or more. I am storing many different arrays representing different things in a single extremely large array to significantly save on memory usage. Hence, instead of having 1 million arrays each of size 100, I have a single array of size 100 million. I store indices (start and stop) to keep track of my data.
I want to get thousands of slices with size 100. If I use the method Arrays.copyOfRange() to get slices, it defeats the purpose of putting everything in a single large array since each slice is a new copy eating up memory.
I have legacy code (in excess of 1 million lines written over the years by many people) that works with its own data (which are smaller arrays). It is not possible to modify the existing code to work with indices (begin, end) in a large array.
If I could somehow return the original array such that the returned array is a reference (or pretends to be) where index 0 is some arbitrary index in the original large array, it would be great.
In C/C++, I can easily return a pointer with a specific offset and length with which the calling code can work.
What are my options in Java?
Edit: I looked at the following similar question, but it does not contain a response to my question. How to get a sub array of array in Java, without copying data?