简体   繁体   English

如何确定ftok共享内存冲突

[英]how to determine ftok shared memory collision

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 . 在尝试了解我在看什么时,我发现它使用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不能保证唯一的键,而且空间碰撞的可能性很小。

ftok() collisions ftok()碰撞

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... 旧版可执行文件可能会导致可怕的内存泄漏...

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. 简便:使用与实际代码相同的参数调用ftok() ,然后比较为相等而返回的两个ints

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 eg segment1 that point to values in segment2, it's up to the application to keep all of the references straight. 如果应用程序想要将值放入例如segment1中,该值指向segment2中的值,则应由应用程序来确保所有引用都是直的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM