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.
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...
Easy: call
ftok()
with the same parameters as your real code, and compare the twoints
that are returned for equality.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.