有没有内存中的文件系统库?

huangapple go评论104阅读模式
英文:

Any library of file system in memory?

问题

我想知道是否有适用于C、C++、Golang、Java和.NET的内存文件系统库。目的是将临时文件保存在内存中,不供用户访问,仅供程序内部使用,所以我不需要RAM驱动器。

英文:

I would like to know if there is any library of file system in memory for c, c++, golang, java, .net

the purpose is to save temp file in memory, not for user access, only for program internal use, so I don't need ram drive.

答案1

得分: 3

有一个名为JimFS的Google开发的库,用于使用Java NIO创建内存中的文件系统,它是开源的,遵循Apache 2许可证,并且在GitHub上可用。它非常容易使用。

try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
  Path foo = fs.getPath("/foo");
  Files.createDirectory(foo);

  Path hello = foo.resolve("hello.txt"); // /foo/hello.txt
  Files.write(hello, ImmutableList.of("hello world"), StandardCharsets.UTF_8);

  // 当你使用完毕后,关闭文件系统以便进行垃圾回收。
}
英文:

There is a Google developped library called JimFS for creating an in-memory File System using the Java NIO it's open source under the Apache 2 License and available on GitHub
it is very easy to use

try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
  Path foo = fs.getPath("/foo");
  Files.createDirectory(foo);

  Path hello = foo.resolve("hello.txt"); // /foo/hello.txt
  Files.write(hello, ImmutableList.of("hello world"), StandardCharsets.UTF_8);

  // Close the FileSystem when you're done with it so it can be garbage collected.
}

答案2

得分: 1

如果使用Java:commons vfs支持RAM文件系统类型。

英文:

If using java : commons vfs supports a RAM file system type

答案3

得分: 0

在C++中,最简单的解决方案是使用std::ostringstream将数据放入字符串中,然后使用std::istringstream重新读取。虽然已经被弃用,但strstream可以让您避免动态分配和复制(假设您事先知道数据的最大大小)。或者您可以轻松编写自己的streambuf来完成。当然,如果您不需要格式化,也可以将数据直接推入std::vector中。

如果我没记错的话,Java也有基于Byte[]的内存流。

英文:

In C++, the simplest solution would be to us an
std::ostringstream to put the data in a string, and then an
std::istringstream to reread it. Although deprecated,
strstream will allow you to avoid the dynamic allocations and
the copies (assuming you know the maximum size of the data
before hand). Or you can easily write your own streambuf to
do it. Or if you don't need formatting, of course, you can just
push the data into an std::vector.

IIRC, Java also has memory based streams (based on Byte[],
I think).

答案4

得分: 0

.Net有一个MemoryStream类,你可以使用它(System.IO):
http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx

英文:

.Net has a MemoryStream class that you could use (System.IO):
http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx

huangapple
  • 本文由 发表于 2013年3月27日 01:15:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/15643388.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定