shared memory content

Hi Qnx Gurus,

I have created a shared memory object between two process and
one process will write into the shared memory and other process will
read from the shared memory.

The issue I am facing is that when I am writing NEW data which is less than
the data written BEFORE in length, the part of the OLD data is also being
displayed.

I tried doing “munmap” and “shm_unlink” but there is NO change in the
result.

Any help will be greatly appreciated.

Thx,
Mankan

Mankan <smankan@nospam.ueidaq.com> wrote:

Hi Qnx Gurus,

I have created a shared memory object between two process and
one process will write into the shared memory and other process will
read from the shared memory.

The issue I am facing is that when I am writing NEW data which is less than
the data written BEFORE in length, the part of the OLD data is also being
displayed.

Well, of course it is still there.

Shared memory is just like any other memory access – if you don’t
overwrite it with new content, the old content is still there.

Of course, I’ll bet you’re dealing with strings, and what you’re
writing to the shared memory is strlen() of your new string, and
that does NOT write the ‘\0’ at the end of the new string, so
you’re actually written bad data to the shared memory, then read
it back thinking it would be a properly nul-terminated string.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Thanks David,

I understood where I made the mistake…

Mankan

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:b57h0v$pep$1@nntp.qnx.com

Mankan <> smankan@nospam.ueidaq.com> > wrote:
Hi Qnx Gurus,

I have created a shared memory object between two process and
one process will write into the shared memory and other process will
read from the shared memory.

The issue I am facing is that when I am writing NEW data which is less
than
the data written BEFORE in length, the part of the OLD data is also
being
displayed.

Well, of course it is still there.

Shared memory is just like any other memory access – if you don’t
overwrite it with new content, the old content is still there.

Of course, I’ll bet you’re dealing with strings, and what you’re
writing to the shared memory is strlen() of your new string, and
that does NOT write the ‘\0’ at the end of the new string, so
you’re actually written bad data to the shared memory, then read
it back thinking it would be a properly nul-terminated string.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Mankan <smankan@nospam.ueidaq.com> wrote:

I have created a shared memory object between two process and
one process will write into the shared memory and other process will
read from the shared memory.

The issue I am facing is that when I am writing NEW data which is less than
the data written BEFORE in length, the part of the OLD data is also being
displayed.

Make sure you are using a semaphore or mutex to control access to the shared
memory or you will see some very strange behaviour that happens periodically
(it will happen more frequently on SMP hardware)

Cheers,
Camz.


Martin Zimmerman camz@passageway.com
Camz Software Enterprises www.passageway.com/camz/qnx/
QNX Programming & Consulting www.qnxzone.com