Java 2 SE 6 doc :
Given a direct byte buffer, the Java virtual machine will make a best effort to perform native I/O operations directly upon it. 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.
- DirectBuffer通过免去中间交换的内存拷贝, 提升IO处理速度;
Java 2 SE 6 doc :
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.
- DirectBuffer在-XX:MaxDirectMemorySize=xxM大小限制下[1], 使用Heap之外的内存, GC对此”无能为力”[2] ,也就意味着规避了在高负载下频繁的GC过程对应用线程的中断影响.
因此, 当系统应用场景满足:
- 大量原生类型数据使用
- 频繁IO操作
- 系统处理响应速度要求快且稳定
典型场景是网络数据传输, 可考虑合理应用DirectBuffer.
- MappedByteBuffer不受-XX:MaxDirectMemorySize=xxM大小限制.
- DirectBuffer何时被回收, 可参见http://www.simaliu.com/archives/274.html.

建议应该可以单独建一个java目录发表Java技术文章
都是高技术文章啊
技术文章~看来工程师们都有写技术文章的习惯
The buffers returned by this method typically have somewhat higher allocation and deallocation costs than non-direct buffers
请问你们有没有测试报告呀?是不是可以这么理解,当CPU已经是瓶颈的时候就不再推荐使用
directBuffer了?
我回复一下 4# 同学的问题,Java 在堆上创建对象是很快的,只需要不到 10 条 CPU 指令,而一个分配内存的 malloc 调用要调用操作系统的内核服务,需要几十条 CPU 指令。显见使用 Heap 之外内存的代价很高。
[...] 前几天看到淘宝数据平台团队的一篇文章《应用 DirectBuffer 提升系统性能 》,DirectBuffer 大体原理就是使用 Java Heap 之外的内存,这些内存不会被通常的 GC 回收,所以就规避了 GC 对应用线程的中断影响,同时也避免了内存拷贝的开销。那我们想知道 DirectBuffer 到底是怎么分配的?这些内存如何被回收? [...]
DirectBuffer 的一些问题:
http://www.simaliu.com/archives/274.html