1. 定义:
关于java堆内存和直接内存的介绍,我在google上面看了一些文章,比较准确的介绍如下:
Java Heap Memory
The Java application runs in the JVM, and the java heap memory is the memory allocated by the JVM for the java application. The JVM is designed to isolate aplications from the machine. Usually talking about Java memory refers to Java heap memory.
you can use -Xmx, -Xms to modify the java heap memory allocation.
Java Direct Memory
Java 1.4 introduced Direct memory.The new IO class is based on channels and buffers for IO operations. NIO adds support for direct ByteBuffers, which can directly operate local memory instead of Java Heap Memory, which will have higher performance because it will avioid copying data between the local heap and Java Heap.
2. 堆外内存和堆内存介绍
如下图所示,Java是C语言写的一段普通的程序,它的级别是linux下面的一个进程,用lsof -p pid命令可以看到进程下的详细信息。用byteBuffer的allocate方法会在jvm虚拟机的堆上分配,