简体   繁体   English

如何像直接访问文件一样使用内存:fread 和 fwrite 函数的类似物?

[英]How to work with memory like direct access files: analogues of fread and fwrite functions?

I need to work in my app with memory buffer like with direct access files.我需要在我的应用程序中使用内存缓冲区,就像直接访问文件一样。 Is exists analogues for fread and fwrite functions? fread 和 fwrite 函数是否存在类似物? C++ C++

I have buffer in memory with data.我在内存中有数据缓冲区。 I want: read data, write data and move pointer in this buffer.我想要:在这个缓冲区中读取数据、写入数据和移动指针。 Like files but with memory and without files.喜欢文件但有内存和没有文件。

I think you mean memory mapped files.我想你的意思是内存映射文件。 It is not supported by the C++ standard, but Boost has a portable implementation here . C++ 标准不支持它,但 Boost 在这里有一个可移植的实现。

Basically, it allows you to access the file through a pointer.基本上,它允许您通过指针访问文件。 The OS will take care of caching and, in general, it is quite efficient.操作系统将负责缓存,并且一般来说,它非常有效。

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

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