Search code examples
c++memoryfile-iofwritefread

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? 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.


Solution

  • I think you mean memory mapped files. It is not supported by the C++ standard, but Boost has a portable implementation here.

    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.