浅谈虚拟机内存区
A direct byte buffer may be created by invoking the allocateDirect factory method of this class. 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. In general it is best to allocate direct buffers only when they yield a measureable gain in program performance. 可是因为直接内存行使allocateDirect建设,它比申请平凡的堆内存必要淹灭更高的机能。不外它不会占用应用的堆内存。以是,当你有大量数据要缓存时,而且它的生命周期又较量长,那么行使直接内存是个不错的选择。但假如该选择不能带来明显的机能晋升,保举行使堆内存。在JDK1.4的NIO中,ByteBuffer有个要领是:
其它直接内受限于本机总内存(包罗RAM及SWAP区可能分页文件)的巨细及处理赏罚器寻址空间的限定。 处事器打点员设置假造机参数时,一样平常会按照现实内存配置-Xmx等参数信息,但常常会忽略掉直接内存,使得各个内存地区的总和大于物理内存限定(包罗物理上的和操纵体系级的限定),从而导致动态扩展时呈现OutOfMemoryError非常。 2.7.2 直接内存的特点
2.7.3 直接内存的非常 动态扩展时呈现OutOfMemoryError非常 2.7.4 直接内存的浸染 基于通道(Channel)与缓冲区(Buffer)的I/O方法,它可以行使Native函数库直接分派堆外内存,然后通过一个存储在Java堆内里的DirectByteBuffer工具作为这块内存的引用举办操纵。这样能在一些场景中明显进步机能,由于停止了在Java堆和Native堆中往返覆制数据。 2.7.5 直接内存的运用 XX:MaxDirectMemorySize=10M 2.7.6 直接内存的行使场景 譬喻在IO处理赏罚时,好比收集发送大量数据时,直接内存会具有更高的服从。 本文基于jdk1.6、1.7 【编辑保举】
点赞 0 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |