文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>内存映射

内存映射

时间:2009-04-19  来源:zhengwenwei_123

Memory-mapped I/O lets us map a file on disk into a buffer in memory so that, when we fetch bytes from the buffer, the corresponding bytes of the file are read. Similarly, when we store data in the buffer, the corresponding bytes are automatically written to the file. This lets us perform I/O without using read or write.

To use this feature, we have to tell the kernel to map a given file to a region in memory. This is done by the mmap function.

Returns: 0 if OK, 1 on error


The flags argument allows us some control over how the memory is flushed. We can specify the MS_ASYNC flag to simply schedule the pages to be written. If we want to wait for the writes to complete before returning, we can use the MS_SYNC flag. Either MS_ASYNC or MS_SYNC must be specified.

An optional flag, MS_INVALIDATE, lets us tell the operating system to discard any pages that are out of sync with the underlying storage. Some implementations will discard all pages in the specified range when we use this flag, but this behavior is not required.

A memory-mapped region is automatically unmapped when the process terminates or by calling munmap directly. Closing the file descriptor filedes does not unmap the region.

相关阅读 更多 +
排行榜 更多 +
兔子跳一跳游戏

兔子跳一跳游戏

休闲益智 下载
球球跳跃游戏

球球跳跃游戏

休闲益智 下载
森林之灵游戏

森林之灵游戏

休闲益智 下载