munmap,mmap的功能是什么 [英] What is the functionality of munmap, mmap

查看:102
本文介绍了munmap,mmap的功能是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试研究一些与FPGA有关的代码时,遇到了munmap,mmap.

When I try to study some piece of code that deals with FPGA, I came across with munmap, mmap.

我在此处中仔细阅读了手册.我仍然不了解此功能的目的.究竟是什么呢?

I go through the manual provided here. I am still not understanding the purpose of this function. What exactly this does?

推荐答案

手册很清楚:

mmap()在调用进程的虚拟地址空间中创建一个新的映射

mmap() creates a new mapping in the virtual address space of the calling process

简而言之,它将大块文件/设备内存/任何内容映射到进程的空间,以便仅通过访问内存就可以直接访问内容.

In short, it maps a chunk of file/device memory/whatever into the process' space, so that it can directly access the content by just accessing the memory.

例如:

fd = open("xxx", O_RDONLY);
mem = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);

将文件内容映射到mem,读取mem就像读取文件xxx的内容.

Will map the file's content to mem, reading mem is just like reading the content of the file xxx.

如果fd是FPGA的某些设备存储器,则mem成为FPGA内容的内容.

If the fd is some FPGA's device memory, then the mem becomes the content of the FPGA's content.

在某些情况下使用起来非常方便并且高效.

It is very convenient to use and efficient in some cases.

这篇关于munmap,mmap的功能是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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