我想使用POSIX共享内存,我的问题是在调用msync()
后使用munmap()
和mmap(MAP_SHARED)
。
msync()
?msync()
之后的文件中可见?msync()
的情况下取消映射共享内存段,是否保存更改?我的印象msync()
仅对将更改应用于基础文件而非共享内存非常有用。
答案 0 :(得分:2)
<强> POSIX 强>
请参阅msync(2)
:
self.tabBarController = [[UITabBarController alloc] init];
//1st view controller
GeneralViewController *infoView = [[GeneralViewController alloc] initWithNibName:@"GeneralViewController" bundle:nil];
UINavigationController *infoTab = [[UINavigationController alloc] initWithRootViewController:infoView];
[infoTab.tabBarItem setTitle:@"Activity"];
//2nd view controller
SupportTabViewController *supportViewCont = [[SupportTabViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *supportTab = [[UINavigationController alloc] initWithRootViewController:supportViewCont];
[supportTab.tabBarItem setTitle:@"Support"];
//3rd view controller
MessageViewController *messageTab = [[MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
UINavigationController *MessageNavTab = [[UINavigationController alloc] initWithRootViewController:messageTab];
[messageTab.tabBarItem setTitle:@"Message"];
//4th view controller
SurveyDefaultViewController *surveyDefaultViewController = [[UIStoryboard storyboardWithName:@"survey" bundle:[NSBundle mainBundle]]instantiateViewControllerWithIdentifier:@"SurveyDefaultViewController"];
UINavigationController *surveyNavTab = [[UINavigationController alloc] initWithRootViewController:surveyDefaultViewController];
[surveyNavTab.tabBarItem setTitle:@"TV Survey"];
[tabBarController setViewControllers:[NSArray arrayWithObjects:infoTab,supportTab,MessageNavTab,surveyNavTab, nil]];
tabBarController.delegate = self;
或{{1}调用msync()
}}。MS_ASYNC
/ MS_SYNC
之前未调用msync()
,实施可能会决定删除更改。这允许旧实现为内存映射(a.k.a页面缓存)和文件I / O(a.k.a缓冲区缓存)使用单独的缓存。
现代实施
现代实现(例如现代Linux)通常实现“统一虚拟内存模型”,它使用相同的缓存进行内存映射和I / O. POSIX或SUSv3不需要它。
在此类实施中:
close()
/ munmap()
之前未调用msync()
,则不会删除更改。close()
是无操作。munmap()
就像MS_ASYNC
。在Linux中,MS_SYNC
只是fsync()
的另一个界面,仅此而已。请参阅msync(2)
手册页和this thread。
<强>参考强>
请参阅“Linux编程接口”,“49.4.4存储器保护和文件访问模式交互”部分。