﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Linux,C/C++,网络......-随笔分类-程序设计</title><link>http://www.cppblog.com/volant/category/8098.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 18 Jun 2009 08:16:02 GMT</lastBuildDate><pubDate>Thu, 18 Jun 2009 08:16:02 GMT</pubDate><ttl>60</ttl><item><title>[导入]共享内存</title><link>http://www.cppblog.com/volant/archive/2009/06/18/87971.html</link><dc:creator>小夜</dc:creator><author>小夜</author><pubDate>Thu, 18 Jun 2009 06:38:00 GMT</pubDate><guid>http://www.cppblog.com/volant/archive/2009/06/18/87971.html</guid><wfw:comment>http://www.cppblog.com/volant/comments/87971.html</wfw:comment><comments>http://www.cppblog.com/volant/archive/2009/06/18/87971.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/volant/comments/commentRss/87971.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/volant/services/trackbacks/87971.html</trackback:ping><description><![CDATA[
进程间通信知识了解不少，今天第一次正式使用，就出问题了。
看看共享内存的原理，操作系统把一块公共的内存区域，映射到进程内存空间中，但映射的内存地址并不能保证映射后的地址一致性（其实一致的可能性很小，基本没有成功过），而此处array执行的地址为创建共享内存进程中正确的数组地址，在新的进程中就不对了。
因此在共享内存中，需要慎重使用指针变量。对于本文中的问题修改很简单，删除int *array，每次使用结构的地址跳过这些额外信息即可，可通过下面的宏函数得到数据域的指针。
<img src="http://blog.csdn.net/volant_hoo/aggbug/4169093.aspx" width="1" height="1"><br>文章来源:<a href="http://blog.csdn.net/volant_hoo/archive/2009/05/11/4169093.aspx">http://blog.csdn.net/volant_hoo/archive/2009/05/11/4169093.aspx</a><img src ="http://www.cppblog.com/volant/aggbug/87971.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/volant/" target="_blank">小夜</a> 2009-06-18 14:38 <a href="http://www.cppblog.com/volant/archive/2009/06/18/87971.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>