如何判断ftok共享内存冲突

发布于 2024-12-17 04:04:43 字数 291 浏览 4 评论 0原文

我正在尝试调试一些遗留代码的问题。在尝试理解我正在查看的内容时,我发现它使用 ftok 构建了两个独特的共享内存空间。我在网上查看它的作用,偶然发现了这个链接。我更深入地研究,发现 ftok 不保证唯一的键,并且空格发生冲突的可能性很小。

ftok() 冲突

因此,我一直试图确定这是否适合我。如何判断是否真的是共享内存空间冲突问题?遗留可执行文件中可能会出现可怕的内存泄漏......

I'm trying to debug a problem with some legacy code. While trying to understand what I'm looking at, I found that it builds two unique shared memory space using ftok. I looked online to see what it does and I stumbled upon this link. I looked deeper and discovered that ftok does not guarantee unique keys and there's a small possibility that the spaces might collide.

ftok() collisions

So, I'm stuck trying to determine whether this is the case for me or not. How do I determine whether it's really an shared memory space collision problem? It can be a horrible memory leak in the legacy executables...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪眸﹌ 2024-12-24 04:04:43

如何判断是否真的是共享内存空间冲突问题?

简单:使用与实际代码相同的参数调用 ftok(),然后比较返回的两个 int 是否相等。

那么只要返回的密钥是唯一的,生成的共享内存空间也不会发生冲突?

只要键不同,两个内存段就完全独立。

应用程序可以自由地将任何值放入它想要的两个段中。如果应用程序想要将值放入例如指向段2 中的值的段1 中,则应用程序需要保持所有引用的一致性。

How do I determine whether it's really an shared memory space collision problem?

Easy: call ftok() with the same parameters as your real code, and compare the two ints that are returned for equality.

So as long as key returned are unique the shared memory space generated are also free from collisions?

So long as the keys are distinct, the two memory segments are completely independent.

The application is free to put any values into the two segments it desires. If the application wants to put values into e.g. segment1 that point to values in segment2, it's up to the application to keep all of the references straight.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文