title: Get a slice of an array without creating a new copy
body: <p>I am trying to find a solution/workaround for slicing extremely large arrays without creating new copies. Here is my problem.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>In C/C++, I can easily return a pointer with a specific offset and length with which the calling code can work.</p>
  
  <p>What are my options in Java?</p>
  
  <p>Edit: I looked at the following similar question, but it does not contain a response to my question.
  <a href="https://stackoverflow.com/questions/3395547/how-to-get-a-sub-array-of-array-in-java-without-copying-data?rq=1">How to get a sub array of array in Java, without copying data?</a></p>