的malloc VS用C MMAP [英] malloc vs mmap in C

查看:164
本文介绍了的malloc VS用C MMAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建了两个方案,一是使用的malloc 和另一个使用 MMAP 。使用的执行时间 MMAP 比使用的malloc

I built two programs, one using malloc and other one using mmap. The execution time using mmap is much less than using malloc.

我知道,例如,当你使用 MMAP 您避免读/写调用该系统。和存储器访问不太

I know for example that when you're using mmap you avoid read/writes calls to the system. And the memory access are less.

但是,还有没有其他原因优点使用 MMAP 在何时的malloc

But are there any other reasons for the advantages when using mmap over malloc?

非常感谢

推荐答案

我假设你指的是使用mmap()和malloc从文件中读取数据。在这种情况下,你pretty有多少钱主穴:

I assume that you are referring to using mmap and malloc for reading data from files. In that case you pretty much got the main point:


  • 使用FREAD / FWRITE你必须做出许多调用操作系统。

  • 使用mmap你似乎得到一个操作访问整个文件。这并不完全正确,因为该操作系统可能映射在一个时间文件的一种内存页面,但它仍然是快了很多

  • using fread/fwrite you have to make many calls to the OS.
  • using mmap you appear to get access to the entire file in one operation. This is not entirely true because the OS probably maps the file one memory page at a time, but it is still a lot faster.

这篇关于的malloc VS用C MMAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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