当前位置: 首页 > news >正文

制作个网站需要多少钱西安建设教育网站

制作个网站需要多少钱,西安建设教育网站,微官网入口,自己做网站需要的技术问题 #xff1a;DirectBuffer 属于堆外存#xff0c;那应该还是属于用户内存#xff0c;而不是内核内存#xff1f;FileChannel 的read(ByteBuffer dst)函数,write(ByteBuffer src)函数中#xff0c;如果传入的参数是HeapBuffer类型,则会临时申请一块DirectBuffer,进行数…问题 DirectBuffer 属于堆外存那应该还是属于用户内存而不是内核内存FileChannel 的read(ByteBuffer dst)函数,write(ByteBuffer src)函数中如果传入的参数是HeapBuffer类型,则会临时申请一块DirectBuffer,进行数据拷贝而不是直接进行数据传输这是出于什么原因DirectBufferJava | native|DirectByteBuffer | mallocd[ address ] -- [ data ]|DirectByteBuffer 自身是一个Java对象在Java堆中而这个对象中有个long类型字段address记录着一块调用 malloc() 申请到的native memory。DirectByteBuffer 自身是(Java)堆内的它背后真正承载数据的buffer是在(Java)堆外——native memory中的。这是 malloc() 分配出来的内存是用户态的。(来自参考文章R大的回答)DirectBuffer 和 HeapBuffer两个都是Buffer ,不同的是前者使用的是堆外内存后者时候的是 JVM 堆内内存。在使用 FileChannel 读写的时候内部实现就有点不同了。以下是FileChannel使用代码public static void main(String[] args) throws Exception{RandomAccessFile aFile new RandomAccessFile(data/nio-data.txt, rw);FileChannel channel aFile.getChannel();String newData New String to write to file... System.currentTimeMillis();// HeapByteBufferByteBuffer buf ByteBuffer.allocate(48);// DirectByteBufferByteBuffer dirctBuf ByteBuffer.allocateDirect(48);buf.clear();buf.put(newData.getBytes());buf.flip();while(buf.hasRemaining()) {channel.write(buf);}}//读取地址FileInputStream fis new FileInputStream(C:\\CloudMusic\\Circadian Eyes - Ferris Wheel.mp3);//写出地址FileOutputStream fos new FileOutputStream(D:\\etc\\cas\\logs\\cas_audit.log);FileChannel fc fis.getChannel();MappedByteBuffer mbb fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());//回刷回磁盘mbb.flip();fos.flush();fc.close();fis.close();如果上面的代码channel.write传入的参数是HeapBuffer类型,则会临时申请一块DirectBuffer,将HeapBuffer中的数据进行数据拷贝到堆外内存然后剩下就是对DirectBuffer进行IO操作为什么直接使用HeapBuffer拷贝数据到内核中然后进行IO操作呢这是因为如果要把一个Java里的 byte[] 对象的引用传给native代码让native代码直接访问数组的内容的话就必须要保证native代码在访问的时候这个 byte[] 对象不能被移动也就是要被“pin”(钉)住。而虚拟机的GC 算法会移动对象导致地址会变化那么后续就会产生错误。详细的见参考资料R大的回答。  OpenJDK的 sun.nio.ch.IOUtil.write(FileDescriptor fd, ByteBuffer src, long position, NativeDispatcher nd) 的实现。static int write(FileDescriptor fd, ByteBuffer src, long position,NativeDispatcher nd)throws IOException{if (src instanceof DirectBuffer)return writeFromNativeBuffer(fd, src, position, nd);// Substitute a native bufferint pos src.position();int lim src.limit();assert (pos lim);int rem (pos lim ? lim - pos : 0);ByteBuffer bb Util.getTemporaryDirectBuffer(rem);try {bb.put(src);bb.flip();// Do not update src until we see how many bytes were writtensrc.position(pos);int n writeFromNativeBuffer(fd, bb, position, nd);if (n 0) {// now update srcsrc.position(pos n);}return n;} finally {Util.offerFirstTemporaryDirectBuffer(bb);}}MappedByteBufferMappedByteBuffer 是 DirectBuffer 的父类,它的读写性能比HeapByteBuffer要高(不然FileChannel 内部实现中也不会用DirectByteBuffer进行操作)。MappedByteBuffer 内部原理主要和操作系统的虚拟存储有关更加直接的联系就是页表相关的知识先阅读以下这篇文章。补充关于 Heap memory 和 Native memory的解释来自stackoverflowHeap memory: memory within the JVM process that is managed by the JVM to represent Java objectsNative memory/Off-heap: is memory allocated within the processes address space that is not within the heap.Direct memory: is similar to native, but also implies that an underlying buffer within the hardware is being shared. For example buffer within the network adapter or graphics display. The goal here is to reduce the number of times the same bytes is being copied about in memory.Finally, depending upon the OS then extra native allocations (assigning of the memory address space) can be carried out via Unsafe alloc and/or by memory mapping a file. Memory mapping a file is especially interesting as it can easily allocate more memory than the machine currently has as physical ram. Also note, that the total address space limit is restricted by the size of a pointer being used, a 32bit pointer cannot go outside of 4GB. Period.参考资料https://www.zhihu.com/question/57374068 (推荐一看)
http://www.sadfv.cn/news/313167/

相关文章:

  • 以公司名称为后缀的邮箱福州搜索优化实力
  • seo网站策划网站页面结构怎么做有利于优化
  • 利辛做网站网站建设和咨询服务合同
  • 网站开发如何下载服务器文档作文网站哪个平台好
  • 台州做网站设计的公司搜索引擎营销策划方案
  • 去公司叫自己做网站不会做wordpress 雷锋模板
  • 泉州网站建设方案详细设计模板在哪里找
  • 做的网站没给我备案搜索引擎优化工具深圳
  • 关于wordpress 反馈优化大师怎么样
  • 网站布局优化策略网站开发一般要多少钱
  • 青海网站制作哪家好百度官网推广平台
  • 西安企业seo外包服务公司西安网站推广优化
  • 宜春网站建设公司旅游网站建设规划报告怎么写
  • 南宁网站建公司吗网站推广适合哪种公司做
  • 网站空格键代码佛山网站建设慕枫
  • 公司网站推广如何做建设网站步骤
  • 手机在网上怎么创建自己的网站网站后台的网址忘记了
  • cms管理手机网站模板济南网站建设公司送400
  • 企业网站模板下载选哪家模板简历
  • 泰州网站建设服务好西安的商城网站建设
  • 中国电信网站备案 密码重置wordpress 数据库主机
  • 做国际贸易哪个网站好wordpress 底部备案号
  • 网站建设分期进行怎么入账广州网站建设网络科技有限公司
  • 遵义市做网站设计公司织梦网站必须下载地址
  • 网站登录入口网页wordpress导航加title
  • 石家庄新钥匙建站佛山网站建设公司哪家性价比高
  • 网站公告建设方案潍坊网站建设报价
  • 网站一级域名申请达州市住房和建设厅网站
  • 清溪东莞网站建设新公司网站建设方案
  • 网站做实名认证大前端wordpress