简体   繁体   English

读取/写入随机访问文件的最快方法?

[英]Fastest way to read/write to Random Access Files?

Note: I have seen similar questions but all referring to large files. 注意:我也看到过类似的问题,但所有问题都涉及大型文件。 This is for small amounts reading and writing constantly, and many files will be written to and read from at once, so performance will be a issue. 这是用于不断进行少量读取和写入,并且一次将写入和读取许多文件,因此性能将成为一个问题。

Currently, I'm using a Random Access File for an "account" it's fast with basic I/O: 目前,我正在为“帐户”使用随机访问文件,使用基本I / O可以很快:

raf.write();

I have seen random access files with file channels and buffered I/O what is the fastest(again for small data.), and could you please supply a example of your proof. 我见过带有文件通道和缓冲I / O的随机访问文件,最快(再次适用于小数据)什么是最快的,能否请您提供一个证明示例。

If you want correctness across multiple read/write processes, you are going to sacrifice performance either to non-buffered APIs like RandomAccessFile, or else to inter-process locking. 如果要在多个读/写过程中保持正确性,则将牺牲性能(例如,RandomAccessFile等非缓冲API),或者牺牲进程间锁定。

You can't validly compare to what you could achieve within a single process without contention. 如果没有争用,您将无法有效地与您在单个过程中可以实现的目标进行比较。

You could investigate MappedByteBuffer, but be aware it brings its own problems in its wake. 您可以研究MappedByteBuffer,但是要知道它带来了自己的问题。

I personally would look into using a database. 我个人会考虑使用数据库。 That's what they're for. 那就是他们的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM