使用read()和write()系统调用访问mmapped()内存 [英] Using read() and write() system calls to access mmapped() memory

查看:101
本文介绍了使用read()和write()系统调用访问mmapped()内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问问是否有可能仅使用诸如read()和write()之类的系统调用来实现mread()函数.我知道标准的C库函数(例如fread()和fwrite())使用一种缓冲区来读取.我想做同样的事情,但是这次我想从缓冲区读取()和写入()到内存映射区域,反之亦然. 例如,我的mread()想从内存映射中读取并存储到缓冲区中.创建一个新的fd用作我的TEMPORARY缓冲区是否有意义?然后,我使用read()从内存映射区域读取到fd ..,然后使用write()将fd中的内容存储到我的实际buff中.
我希望我很清楚:) ..谢谢您的帮助!

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!

推荐答案

我希望我很清楚

I hope I was clear

不幸的是,不是很好.但这听起来像您想使用pipe系统调用.它会打开两个fds.在写端写的任何内容都可以在读端读.如果在单个线程中执行所有这些操作,则必须小心,因为您可能会用完缓冲区空间,并且读/写调用将无限期挂起.

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.

这篇关于使用read()和write()系统调用访问mmapped()内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆