为什么Socket获取的字节流先要拷贝到堆外内存然后再复制到Heap区域
playboy0651140
2015-09-21
为什么Socket获取的字节流先要拷贝到堆外内存然后再复制到Heap区域呢?是什么原因造成从堆内内存获取字节流必须要经过
|
|
playboy0651140
2015-09-22
Operating systems perform I/O operations on memory areas. These memory areas, as far as the operating system is concerned, are contiguous sequences of bytes. It's no surprise then that only byte buffers are eligible to participate in I/O operations. Also recall that the operating system will directly access the address space of the process, in this case the JVM process, to transfer the data. This means that memory areas that are targets of I/O perations must be contiguous sequences of bytes. In the JVM, an array of bytes may not be stored contiguously in memory, or the Garbage Collector could move it at any time. Arrays are objects in Java, and the way data is stored inside that object could vary from one JVM implementation to another.
For this reason, the notion of a direct buffer was introduced. Direct buffers are intended for interaction with channels and native I/O routines. They make a best effort to store the byte elements in a memory area that a channel can use for direct, or raw, access by using native code to tell the operating system to drain or fill the memory area directly. 我理解了下说在堆内存中在gc的时候涉及到字节数组的拷贝所以socket不能直接操作那个区域,但是并不理解 In the JVM, an array of bytes may not be stored contiguously in memory这句话的含义 |
相关讨论
相关资源推荐
- java堆外内存 共享_Java堆外内存之一:堆外内存场景介绍(对象池VS堆外内存)...
- JDK核心JAVA源码解析(4) - 堆外内存、零拷贝、DirectByteBuffer以及针对于NIO中的FileChannel的思考
- JVM(Java虚拟机)详解(JVM 内存模型、堆、GC、直接内存、性能调优)
- socket 收不到netty客户端消息_Netty高性能之道
- Java网络编程(6) - Netty高性能体现,Netty为什么快?高性能的三大要素?Netty的高能性在什么地方?Netty的线程模型?Netty的零拷贝技术是怎么样?Netty内存池是怎么样的?
- JVM -- JVM内存结构:程序计数器、虚拟机栈、本地方法栈、堆、方法区(二)
- 支撑百万并发的“零拷贝”技术,你了解吗?
- 网络编程(二):BIO、NIO、Reactor模式、直接内存、零拷贝理解
- 玩碎Java之零拷贝
- Linux零拷贝解析