ByteBuffer源码阅读笔记

A byte buffer is either direct or non-direct.

字符缓冲区可以是直接的或非直接的

Given a direct byte buffer, the Java virtual machine will make a best effort to perform native I/O operations directly upon it.

给定一个字符缓冲区,Java虚拟机将会尽最大的努力直接在它上面执行本地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.

也就是说,它将会试图避免任一一个底层操作系统I/O操作的每一次调用之前复制这个缓冲区的内容去一个中间缓冲区(或从一个中间缓冲区复制到这个缓冲区)(翻译君:感觉是这个意思:它尽量避免任一一个底层操作系统I/O每次调用之前,发生对这个缓冲区的操作。换句话:尽量在操作系统本地I/O读取之后再操作

A direct byte buffer may be created by invoking the allocateDirect factory method of this class.

直接缓冲区可以通过调用这个类的工厂方法allocateDirect创建

The buffers returned by this method typically have somewhat higher allocation and deallocation costs than non-direct buffers.

这个方法返回的缓冲区和不直接缓冲区相比,通常在分配和释放上的成本有点高。

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.

直接缓冲区的内容可能会在普通的垃圾回收堆之外,因此他们对应用程序内存占用的影响可能不明显。

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.

因此,建议将直接缓冲区主要分配给受底层操作系统本地I/O操作管制的大型、长寿命缓冲区

In general it is best to allocate direct buffers only when they yield a measureable gain in program performance.

总的来说,最好只有当它在程序的性能中产生可观增益时,再分配直接缓冲区。

A direct byte buffer may also be created by mapping a region of a file directly into memory.

直接字符缓冲区也可通过将一个文件的区域直接映射到内存中来创建。

An implementation of the Java platform may optionally support the creation of direct byte buffers from native code via JNI.

Java平台的一个实现可以支持直接字符缓冲区从原生代码中通过JNI创建。

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.

如果其中一种缓冲区的实例指向一个不可访问的内存区域,那么访问该区域的尝试将不会改变缓冲区的内容,并将导致在访问时或稍后的时间抛出未指定的异常。

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.

一个字符缓冲区是否为直接或非直接的可以通过调用它的isDirect方法来确定。提供这种方法,以便在性能关键代码中实现显式缓冲区管理。

Invocation chaining

链式调用

Methods in this class that do not otherwise have a value to return are specified to return the buffer upon which they are invoked.

这个类中没有返回值的方法被指定为返回它们被调用的缓冲区。

This allows method invocations to be chained.

这允许链式的调用方法。

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);

举个例子,这些序列的语句,可以通过单个语句来替换。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,651评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,468评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,931评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,218评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,234评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,198评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,084评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,926评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,341评论 1 311
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,563评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,731评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,430评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,036评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,676评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,829评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,743评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,629评论 2 354

推荐阅读更多精彩内容