2

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...

Community
  • 1
  • 1
adi
  • 23
  • 2

1 Answers1

0

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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • So as long as key returned are unique the shared memory space generated are also free from collisions? – adi Nov 20 '11 at 23:16
  • Thanks! I'll add in some debug code for that just in case. Then a unique file name with the current PID extension should be good enough. It's mostly a problem elsewhere... Thanks for the clarification – adi Nov 21 '11 at 00:45