A byte buffer is either direct or non-direct.
字符緩沖區(qū)可以是直接的或非直接的
Given a direct byte buffer, the Java virtual machine will make a best effort to perform native I/O operations directly upon it.
給定一個字符緩沖區(qū),Java虛擬機將會盡最大的努力直接在它上面執(zhí)行本地I/O操作。
That is, it will attempt to avoid copying the buffer's content to (or from) an intermediate buffer before (or after) each invocation of one of the underlying operating system's native I/O operations.
也就是說,它將會試圖避免任一一個底層操作系統(tǒng)I/O操作的每一次調(diào)用之前復制這個緩沖區(qū)的內(nèi)容去一個中間緩沖區(qū)(或從一個中間緩沖區(qū)復制到這個緩沖區(qū))(翻譯君:感覺是這個意思:它盡量避免任一一個底層操作系統(tǒng)I/O每次調(diào)用之前,發(fā)生對這個緩沖區(qū)的操作。換句話:盡量在操作系統(tǒng)本地I/O讀取之后再操作)
A direct byte buffer may be created by invoking the allocateDirect factory method of this class.
直接緩沖區(qū)可以通過調(diào)用這個類的工廠方法allocateDirect創(chuàng)建
The buffers returned by this method typically have somewhat higher allocation and deallocation costs than non-direct buffers.
這個方法返回的緩沖區(qū)和不直接緩沖區(qū)相比,通常在分配和釋放上的成本有點高。
The contents of direct buffers may reside outside of the normal garbage-collected heap, and so their impact upon the memory footprint of an application might not be obvious.
直接緩沖區(qū)的內(nèi)容可能會在普通的垃圾回收堆之外,因此他們對應用程序內(nèi)存占用的影響可能不明顯。
It is therefore recommended that direct buffers be allocated primarily for large, long-lived buffers that are subject to the underlying system's native I/O operations.
因此,建議將直接緩沖區(qū)主要分配給受底層操作系統(tǒng)本地I/O操作管制的大型、長壽命緩沖區(qū)
In general it is best to allocate direct buffers only when they yield a measureable gain in program performance.
總的來說,最好只有當它在程序的性能中產(chǎn)生可觀增益時,再分配直接緩沖區(qū)。
A direct byte buffer may also be created by mapping a region of a file directly into memory.
直接字符緩沖區(qū)也可通過將一個文件的區(qū)域直接映射到內(nèi)存中來創(chuàng)建。
An implementation of the Java platform may optionally support the creation of direct byte buffers from native code via JNI.
Java平臺的一個實現(xiàn)可以支持直接字符緩沖區(qū)從原生代碼中通過JNI創(chuàng)建。
If an instance of one of these kinds of buffers refers to an inaccessible region of memory then an attempt to access that region will not change the buffer's content and will cause an unspecified exception to be thrown either at the time of the access or at some later time.
如果其中一種緩沖區(qū)的實例指向一個不可訪問的內(nèi)存區(qū)域,那么訪問該區(qū)域的嘗試將不會改變緩沖區(qū)的內(nèi)容,并將導致在訪問時或稍后的時間拋出未指定的異常。
Whether a byte buffer is direct or non-direct may be determined by invoking its isDirect method. This method is provided so that explicit buffer management can be done in performance-critical code.
一個字符緩沖區(qū)是否為直接或非直接的可以通過調(diào)用它的isDirect方法來確定。提供這種方法,以便在性能關鍵代碼中實現(xiàn)顯式緩沖區(qū)管理。
Invocation chaining
鏈式調(diào)用
Methods in this class that do not otherwise have a value to return are specified to return the buffer upon which they are invoked.
這個類中沒有返回值的方法被指定為返回它們被調(diào)用的緩沖區(qū)。
This allows method invocations to be chained.
這允許鏈式的調(diào)用方法。
The sequence of statements
bb.putInt(0xCAFEBABE);
bb.putShort(3);
bb.putShort(45);
can, for example, be replaced by the single statement
bb.putInt(0xCAFEBABE).putShort(3).putShort(45);
舉個例子,這些序列的語句,可以通過單個語句來替換。