Using read() and write() system calls to access mmapped() memory

妖精的绣舞 提交于 2020-01-06 15:19:07

问题


I wish to ask whether is it possible to implement an mread() function using only system calls such as read() and write(). I know that the standard C library functions such as fread() and fwrite() use a type of buffer to read. I want to do the same but this time I want to read() and write() from a buffer to a memory mapped region and vice versa. For example my mread() wants to read from memory map and store into buffer. Does it make sense to create a new fd just to use it as my TEMPORARY buffer. Then I use read() to read from memory mapped region into the fd..and then use write() to store the contents in fd into my actual buff.
I hope I was clear :) ..Thank you for your help!


回答1:


I hope I was clear

Unfortunately, not very. But it sounds like you want to use the pipe system call. It opens two fds. Whatever's written on the write end can be read on the read end. If you're doing all of this in a single thread you have to be careful though, because you might run out of buffer space and the read/write call will then hang indefinitely.



来源:https://stackoverflow.com/questions/24350294/using-read-and-write-system-calls-to-access-mmapped-memory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!