cuốn sách gpt4 ai đã làm

Java - IntBuffer 包装

In lại Tác giả: Taklimakan 更新时间:2023-11-03 04:20:58 26 4
mua khóa gpt4 Nike

我正在使用 :

读取整数文件
int len = (int)(new File(file).length());
FileInputStream fis = new FileInputStream(file);
byte buf[] = new byte[len];
fis.read(buf);
IntBuffer up = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();

但是,它会在内存中创建两个文件副本,1) 字节数组副本 2) IntBuffer 副本。

是否可以以这种方式使用代码,从而在内存中只创建一个副本?

câu trả lời hay nhất

我看过的 Oracle 的 javadoc 和实现表明您所说的是不正确的。 javadocs 说:

public static ByteBuffer wrap(byte[] array)

Wraps a byte array into a buffer.

The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa.

代码显示传递到ByteBuffer.wrap củamảng 被简单地分配为Bộ đệm byte 的内部数组。 ByteBuffer.asIntBuffer 方法简单地展示了使用 Bộ đệm byte của bộ đệm nội bộ 的创建。

关于Java - IntBuffer 包装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11438982/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress