获取数组的一个切片,而无需创建一个新的副本 [英] Get a slice of an array without creating a new copy

查看:97
本文介绍了获取数组的一个切片,而无需创建一个新的副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个解决方案/解决方法切片非常大的阵列,而无需创建新的副本。这里是我的问题。

I am trying to find a solution/workaround for slicing extremely large arrays without creating new copies. Here is my problem.

假设我有一个大数组大小在100亿以上的双/ INT的。我存储许多不同的阵列重新presenting不同的东西在一个非常大的阵列上的内存使用情况,以节省显著。因此,而不是让每个大小为100 100万阵列,我有大小100亿单个阵列。我存储指数(启动和停止),以保持我的数据跟踪。

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.

我想如果我使用的方法Arrays.copyOfRange()来获取片获得数千片的大小为100,它违背了把一切在一个单一的大阵,因为每片的目的,是一个新的副本吃内存

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.

我有遗留code(超过许多人写在年51万用户线),与它自己的数据(这是更小的数组)的作品。这是不可能修改现有code在大阵指数(开始,结束)的工作。

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.

如果我能以某种方式回到原来的阵列,返回的数组是一个引用(或pretends来定),其中索引0是原来的大阵中的一些任意的指数,这将是巨大的。

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.

在C / C ++,我可以很容易地返回一个指针与特定的偏移量和长度与调用code能正常工作。

In C/C++, I can easily return a pointer with a specific offset and length with which the calling code can work.

什么是我的Java选项?

What are my options in Java?

编辑:我看着下面类似的问题,但它不包含我的问题的回应。
<一href=\"http://stackoverflow.com/questions/3395547/how-to-get-a-sub-array-of-array-in-java-without-copying-data?rq=1\">How要获得Java数组的数组子,不复制数据?

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?

推荐答案

有关int类型的数组,您可以在包装的 IntBuffer 。你也可以换一个数组的一个切片。

For an array of int values, you can wrap in an IntBuffer. You can also wrap a slice of an array.

int[] largeArray = . . .

// create a slice containing the elements 100 through 149 (50 elements):
IntBuffer slice = IntBuffer.wrap(largeArray, 100, 50);

这篇关于获取数组的一个切片,而无需创建一个新的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆