如何获得Java数组的数组子,不复制数据? [英] How to get a sub array of array in Java, without copying data?

查看:131
本文介绍了如何获得Java数组的数组子,不复制数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些班级图书馆,我的数据,这些数据被读入缓冲区工作。是否有可能以某种方式一次又一次地避免复制阵列,传递的数据越陷越深零部件到加工方法?嗯,这听起来很奇怪,但在我的具体情况,有一个特殊的作家,其将数据分割成块,并且个别写入不同的位置,所以它只是执行System.arraycopy,得到它所需要并调用底层的作家,与新子阵列。而且这种情况发生很多次。什么是重构这样code的最佳方法?

I have some library of classes, working with my data, which is being read into buffer. Is it possible somehow to avoid copying arrays again and again, passing parts of data deeper and deeper into processing methods? Well, it sounds strange, but in my particular case, there's a special writer, which divides data into blocks and writes them individually into different locations, so it just performs System.arraycopy, gets what it needs and calls underlying writer, with that new sub array. And this happens many times. What is the best approach to refactor such code?

推荐答案

很多类在Java中接受数组作为参数的一个子集。例如。 Writer.write(CHAR CBUF [],诠释了,诠释LEN)。也许这已经足以满足您的用例。

Many classes in Java accept a subset of an arrays as parameter. E.g. Writer.write(char cbuf[], int off, int len). Maybe this already suffices for your usecase.

这篇关于如何获得Java数组的数组子,不复制数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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