io

花1K内存实现高效I/O的RandomAccessFile类

流过昼夜 提交于 2020-02-29 22:21:23
主体: 目前最流行的J2SDK版本是1.3系列。使用该版本的开发人员需文件随机存取,就得使用RandomAccessFile类。其I/O性能较之其它常用开发语言的同类性能差距甚远,严重影响程序的运行效率。 开发人员迫切需要提高效率,下面分析RandomAccessFile等文件类的源代码,找出其中的症结所在,并加以改进优化,创建一个"性/价比"俱佳的随机文件访问类BufferedRandomAccessFile。 在改进之前先做一个基本测试:逐字节COPY一个12兆的文件(这里牵涉到读和写)。 读 写 耗用时间(秒) RandomAccessFile RandomAccessFile 95.848 BufferedInputStream + DataInputStream BufferedOutputStream + DataOutputStream 2.935 我们可以看到两者差距约32倍,RandomAccessFile也太慢了。先看看两者关键部分的源代码,对比分析,找出原因。 1.1.[RandomAccessFile] public class RandomAccessFile implements DataOutput, DataInput { public final byte readByte() throws IOException { int ch = this

DataInputStream,DataOutputStream读写UTF8原理

大憨熊 提交于 2020-02-29 21:43:17
今晚上写代码玩,用到 java.io.RandomAccessFile.writeUTF(String) 函数,而文件默认保存为gbk,显然是乱码。突然想起来去看看存储编码规则,就去找了些文章了解writeUTF(String)的原理,在此记录。 首先需要弄明白unicode与utf8的表示规则,搜到@Feng哥的一篇文章《 字符编码笔记:ASCII,Unicode和UTF-8 》,写的很明白,在此招录一段: | Unicode符号范围 | UTF-8编码方式 | 0000 0000-0000 007F | 0xxxxxxx | 0000 0080-0000 07FF | 110xxxxx 10xxxxxx | 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx | 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 下面,还是以汉字"严"为例,演示如何实现UTF-8编码。 已知"严"的unicode是4E25(100111000100101),根据上表,可以发现4E25处在第三行的范围内(0000 0800-0000 FFFF),因此"严"的UTF-8编码需要三个字节,即格式是"1110xxxx 10xxxxxx 10xxxxxx"。然后,从"严"的最后一个二进制位开始

Futex throughput on Linux

♀尐吖头ヾ 提交于 2020-02-28 07:03:41
问题 I have an async API which wraps some IO library. The library uses C style callbacks, the API is C++, so natural choice (IMHO) was to use std::future/std::promise to build this API. Something like std::future<void> Read(uint64_t addr, byte* buff, uint64_t buffSize) . However, when I was testing the implementation I saw that the bottleneck is the future/promise , more precisely, the futex used to implement promise/future . Since the futex, AFAIK, is user space and the fastest mechanism I know

Futex throughput on Linux

…衆ロ難τιáo~ 提交于 2020-02-28 07:03:38
问题 I have an async API which wraps some IO library. The library uses C style callbacks, the API is C++, so natural choice (IMHO) was to use std::future/std::promise to build this API. Something like std::future<void> Read(uint64_t addr, byte* buff, uint64_t buffSize) . However, when I was testing the implementation I saw that the bottleneck is the future/promise , more precisely, the futex used to implement promise/future . Since the futex, AFAIK, is user space and the fastest mechanism I know

IO诊断文档

不想你离开。 提交于 2020-02-26 09:00:08
利用 sys 库进行 IO 信息诊断 1、 table 相关 1.1 查询表的 IO 请求数量 mysql> select concat_ws('.',table_schema,table_name) 'table', io_read_requests, io_write_requests, io_misc_requests from sys.schema_table_statistics_with_buffer\G *************************** 1. row *************************** table: universe.u_delay # 表名 io_read_requests: 11 # 读请求数量 io_write_requests: 4 # 写请求数量 io_misc_requests: 15 # IO总请求数量 1.2 查询表的 IO 请求字节数 mysql> select concat_ws('.',table_schema,table_name) 'table', io_read, io_write from sys.schema_table_statistics_with_buffer\G *************************** 1. row ***************************

Efficiency of fopen, fclose

早过忘川 提交于 2020-02-24 10:10:20
问题 If iteratively writing to a file in a nested for loop, is there any difference in efficiency to open the file before the loop and close it after, rather than open and close within? See the following: int main(){ FILE *file1; char filename; int i, j, N, M; for(i=0; i<N; i++){ file1=fopen(filename, "a"); for(j=0; j<M; j++){ fprintf(file1,"%d %d\n", i, j); } fclose(file1); } return 1; } or int main(){ FILE *file1; char filename; int i, j, N, M; file1=fopen(filename, "a"); for(i=0; i<N; i++){ for

Why there is no Path constructor in java.nio.files.Path?

烂漫一生 提交于 2020-02-24 04:38:28
问题 The Path class has no documented constructor, but one creates instances via. Paths.get( "...." ) which is a shorthand for FileSystems.getDefault().getPath( "..." ) . So can someone explain this design decission? 回答1: can someone explain this design decision? It is because JSR 203 allows paths to be issued from more than one FileSystem, unlike File , which is always linked to the file system the JVM lives on. In JSR 203, this filesystem is called the default filesystem . You can get a

What's the connection between flags and mode in open file function in C

一个人想着一个人 提交于 2020-02-23 04:00:12
问题 I'm a beginner in C, have a question about the flags and mode paramaters in open file function in C so C's open function is : int open(char *filename, int flags, mode_t mode); and some macros for the flags are: O_RDONLY : Reading only O_WRONLY : Writing only O_RDWR : Reading and writing and the mode bit is something like: What I don't understand is, let say we have a open function as: fd = Open("foo.txt", O_RDONLY, S_IWOTH); so O_RDONLY specifies that we can only read the file, but S_IWOTH

Google IO & 2019

蓝咒 提交于 2020-02-21 05:32:52
Google IO & 2019 Google IO Recap https://www.techradar.com/news/google-io-2019-keynote https://events.google.com/io/recap blogs & news https://www.theverge.com/2019/5/7/18531198/google-io-summary-keynote-news-highlights-recap-2019 https://bgr.com/2019/05/07/google-io-2019-top-10-announcements-pixel-3a-android-q-beta-3/ https://www.androidauthority.com/google-io/ 来源: https://www.cnblogs.com/xgqfrms/p/11063934.html

Getting path to the parent folder of the solution file using C#

回眸只為那壹抹淺笑 提交于 2020-02-20 07:14:50
问题 I am a beginner in C#, and I have a folder from which I am reading a file. I want to read a file which is located at the parent folder of the solution file. How do I do this? string path = ""; StreamReader sr = new StreamReader(path); So if my file XXX.sln is in C:\X0\A\XXX\ then read the .txt files in C:\X0\A\ . 回答1: Try this: string startupPath = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName,"abc.txt"); // Read the file as one